I'm currently trying to create a quiz in python using tkinter. I'd like to use the RadioButtons as multiple choices, but I don't really know how to connect the selected choice with the CommandButton. I found a similar program to the one I'm trying to create, but still I don't understand it. Could someone please help me?
I fail to understand why in the function is called call(par)
and the command is command =lambda: call(correct.get())
import Tkinter as tk
root = tk.Tk()
def call(par):
if par:
lab2 = tk.Label(root, text='CORECT!!!!').grid(row=4)
else:
lab2 = tk.Label(root, text='of corse your wrong').grid(row=4)
lab2 = tk.Label(root, text='how could you be so stupid?').grid(row=5)
correct = tk.BooleanVar()
rad = tk.Radiobutton(root, text='yes', variable=correct, value=True)
rad2 = tk.Radiobutton(root, text='no', variable=correct, value=False)
lab = tk.Label(root, text='Is the maker awsome?')
btn = tk.Button(root, text='submit', command=lambda: call(correct.get()))
lab.grid(row=0)
rad.grid(row=2, column=0)
rad2.grid(row=2, column=1)
btn.grid(row=3)
tk.mainloop()