我目前正在尝试使用tkinter在python中创建一个测验。我想将RadioButtons用作多种选择,但我真的不知道如何将所选择的选项与CommandButton连接起来。我找到了一个与我试图创建的类似的程序,但我仍然不理解它。有人可以帮助我吗?
我无法理解为什么在函数中调用call(par)
而命令是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()