我有一个问题,这个程序的命令不工作,当我按下按钮
from Tkinter import *
import random
MenuP = Tk()
MenuP.geometry("540x960")
def Respuesta1(a):
if a == 1:
resp = random.randint(0,4)
if resp == 0:
r = 3
elif resp == 1 or resp == 2:
r = 5
else:
r = 7
if a == 2:
resp = random.randint(0,4)
if resp == 0:
r = 1
elif resp == 3 or resp == 2:
r = 5
else:
r = 3
print r
C1 = Button(MenuP, text = "1", command = Respuesta1(1)).place(x = 100,y = 100)
C2 = Button(MenuP, text = "2", command = Respuesta1(2)).place(x = 300,y = 100)
MenuP.mainloop()
当程序启动时,在我按下按钮之前会打印数字。如果有人知道什么,请回答。谢谢
您需要更改以下行:
为此:
通过使用
lambda
函数,您可以将所需的变量传递给函数,而无需在开始时调用它。它被直接调用,因为Tkinter将您传递的内容作为command
进行评估相关问题 更多 >
编程相关推荐