Why, if I put a "normal" call to the method button1Click()
in the bind
call, does my program not even start? By removing the parenthesis the problem is solved.
I'm using this program as reference: Thinking in Tkinter
Also, why should I add the event
argument to my button1Click()
method?
from Tkinter import *
class MyApp:
def __init__(self, parent):
self.myParent = parent
self.myContainer1 = Frame(parent)
self.myContainer1.pack()
self.button1 = Button(self.myContainer1)
self.button1.configure(text="OK", background= "green")
self.button1.pack(side=LEFT)
self.button1.bind("<Button-1>", self.button1Click) # <--- no () !
def button1Click(self, event):
self.button2 = Button(self.myContainer1, text="lol")
self.button2.bind("<Button-1>", self.button1Click)
self.button2.pack()
root = Tk()
myapp = MyApp(root)
root.mainloop()