【发布时间】:2026-01-01 22:25:02
【问题描述】:
每次单击按钮并执行函数时,我都会尝试打印随机整数,但是,除非我重新启动程序,否则我只会得到相同的结果。
这是我的代码:
num1= randint(0,9)
testbtn_txt = tk.StringVar()
testbtn = tk.Button(root, textvariable=testbtn_txt, command=lambda:testfunc(), font="Arial", bg="#808080", fg="white", height=1, width=10)
testbtn_txt.set("Test")
testbtn.grid(row=10, column=0, columnspan=2, pady=5, padx=5)
def testfunc():
print(num1)
那么我该怎么做呢?
【问题讨论】: