def play():
wind2 = tk.Toplevel()
v = tk.IntVar()
ques = ["Identify the least stable ion amongst the following.",
"The set representing the correct order of first ionisation potential is",
"The correct order of radii is"]
o1 = ["", "Li⁺", "Be⁻", "B⁻", "C⁻"]
o2 = ["", "K > Na > Li", "Be > Mg >Ca", "B >C > N", "Ge > Si >C"]
o3 = ["", "N < Be < B", "F⁻ < O²⁻ < N³⁻", "Na < Li < K", "Fe³⁺ < Fe⁴⁺ < Fe²⁺"]
choice=[o1, o2, o3]
qsn = tk.Label(wind2, text = ques[0])
qsn.pack()
def correct():
selected=v.get()
print(selected)
r1 = tk.Radiobutton(wind2, text = o1[1], variable = v, value = 1, command=correct)
r2 = tk.Radiobutton(wind2, text = o1[2], variable = v, value = 2, command=correct)
r3 = tk.Radiobutton(wind2, text = o1[3], variable = v, value = 3, command=correct)
r4 = tk.Radiobutton(wind2, text = o1[4], variable = v, value = 4, command=correct)
r1.pack()
r2.pack()
r3.pack()
r4.pack()
def nxt():
n = random.randint(1,2)
qsn['text'] = ques[n]
r1['text'] = choice[n][1]
r2['text'] = choice[n][2]
r3['text'] = choice[n][3]
r4['text'] = choice[n][4]
nbut = tk.Button(wind2, text = "next", command = lambda: nxt)
nbut.pack()
我尝试使用按钮nbut
更改问题,但它不起作用。我尝试在函数外部使用randint
并传递它,但按钮只起作用一次
1条答案
按热度按时间xbp102n01#
变更
为了这个。
原因很简单。
当
nbut
单击时,您不是在调用nxt
函数,而是在调用lambda
函数。但是,由于您将函数名放在lambda函数中,而没有使用括号,因此nxt
函数永远不会执行。