Reputation: 847
I'm new to python and I have to program some sort of gui. But the gui consist of child windows, currently there is one child window. The prolem is at startup the child window also starts up. It's supposed to wait until the button has been clicked and then launch the child window. I have no idea why it beheaves like this....
#!/usr/bin/env python
from Tkinter import *
import tkMessageBox as box
import rospy
class gui(Frame):
def __init__(self, parent):
Frame.__init__(self, parent, background="white")
self.parent = parent
self.initUI()
def initUI(self):
self.parent.title("Baxter analyse tool")
menubar = Menu(self.parent)
self.parent.config(menu=menubar)
fileMenu = Menu(menubar)
submenu = Menu(fileMenu)
submenu.add_command(label="camera tool", command=self.camera_window())
submenu.add_command(label="range tool")
submenu.add_command(label="control tool")
submenu.add_command(label="sonar tool")
submenu.add_command(label="quick check tool")
fileMenu.add_cascade(label="tools", menu=submenu, underline=0)
fileMenu.add_separator()
fileMenu.add_command(label="Exit", command=self.onExit)
menubar.add_cascade(label="File", menu=fileMenu)
menubar.add_command(label="about", command=self.about)
def camera_window(self):
cameraGui = CameraGui()
def about(self):
box.showinfo("Baxter","Analyse tool.")
def onExit(self):
self.quit()
class CameraGui(object):
def __init__(self):
self.initUI()
def initUI(self):
win = Toplevel()
Label(win, text="testestest").pack()
Button(win, text="hello", command=win.destroy).pack()
def main():
rospy.init_node('baxter_lput_analyse_tool')
root = Tk()
root.geometry("{0}x{1}+0+0".format(root.winfo_screenwidth()/2, root.winfo_screenheight()-50))
root.focus_set()
root.bind("<Escape>", lambda e: e.widget.quit())
app = gui(root)
root.mainloop()
if __name__=='__main__':
main()
The program runs fine just that it automatically opens the child window
Upvotes: 0
Views: 1422
Reputation: 2689
Don't call the function self.camera_window()
.
Remove the ()
. Your self.camera_window
method gets called as soon as the main loop starts.
Do this:
submenu.add_command(label="camera tool", command=self.camera_window)
Or if you want to send some argument then:
submenu.add_command(label="camera tool", command=lambda:self.camera_window(args))
Upvotes: 3