3

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)
Bryan Oakley
  • 310,202
  • 36
  • 445
  • 584

1 Answers1

5

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.

TheLizzard
  • 4,696
  • 2
  • 8
  • 22