Reputation: 31
I am trying to get a tkinter quiz to work for a school project but can't seem to get buttons to work. By virtue of how my loops work I cant make a function for this.
ansBtn1 = tk.Button(self.master, text=question[3], command=(lambda: choice = question[3]))
ansBtn1.grid(row=1, column=0)
Upvotes: 3
Views: 681
Reputation: 7680
Define a normal function:
def function():
global choise
choise = question[3]
ansBtn1 = tk.Button(self.master, text=question[3], command=function)
ansBtn1.grid(row=1, column=0)
If you really really want to use lambda
, you can use the walrus operator. For more info read this.
Upvotes: 5