Hi!
The following Tkinter buttons should call opt_def with opt as 1 or 2 depending on which button is pressed (see code).
from Tkinter import *
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.opt1 = Button(frame, text="Opt1", command=self.opt_def(1))
self.opt1.pack(side=TOP)
self.opt2 = Button(frame, text="Opt2", command=self.opt_def(2))
self.opt2.pack(side=BOTTOM)
def opt_def(self, opt):
print 'You have choosen option', opt
root = Tk()
app = App(root)
root.mainloop()
But when the code is ran (no Tkinter buttons pressed) it returns this:
>>>
You have choosen option number 1
You have choosen option number 2
Why does this happens and how do I fix it? Sorry about my spelling btw, I'm not american