All Tkinter Functions Run When Program Starts
I am having a very weird problem that I've never had before when using tkinter. Anywhere that I set a command for a widget such as a button or a menu item, the command runs when th
Solution 1:
Remove the ()
s in your command definitions. Right now, you are calling the function and binding the return values to command
parameter whereas you need to bind the functions itself so that later on they could be called.
So a line like this:
filemenu.add_command(label="New...", command=self.new())
should actually be this:
filemenu.add_command(label="New...", command=self.new)
(You actually do this in one place correctly: filemenu.add_command(label="Exit", command=app.quit)
)
Solution 2:
filemenu.add_command(label="Open...", command=self.open())
filemenu.add_command(label="New...", command=self.new())
filemenu.add_command(label="Open...", command=self.open())
filemenu.add_command(label="Save", command=self.save())
In these lines, you have to pass the reference to the functions. You are actually calling the functions.
filemenu.add_command(label="Open...", command=self.open)
filemenu.add_command(label="New...", command=self.new)
filemenu.add_command(label="Open...", command=self.open)
filemenu.add_command(label="Save", command=self.save)
Post a Comment for "All Tkinter Functions Run When Program Starts"