【发布时间】:2019-06-17 18:14:06
【问题描述】:
我希望在按下按钮后执行我的功能。但是当我运行程序时,按钮会在我单击它们之前调用所有按钮的函数。当我按下按钮时,在我的输出显示后,所有按钮都不起作用。
程序中的其他按钮都以相同的方式正常工作。
#all the buttons calling the same function buttonEntry(num) with different parameters
button1 = Button(frame_bottom, text="1", width="20", height="6", bg=buttonColor, command=buttonEntry("1"))
button2 = Button(frame_bottom, text="2", width="20", height="6", bg=buttonColor, command=buttonEntry("2"))
button3 = Button(frame_bottom, text="3", width="20", height="6", bg=buttonColor, command=buttonEntry("3"))
button4 = Button(frame_bottom, text="4", width="20", height="6", bg=buttonColor, command=buttonEntry("4"))
button5 = Button(frame_bottom, text="5", width="20", height="6", bg=buttonColor, command=buttonEntry("5"))
button6 = Button(frame_bottom, text="6", width="20", height="6", bg=buttonColor, command=buttonEntry("6"))
button7 = Button(frame_bottom, text="7", width="20", height="6", bg=buttonColor, command=buttonEntry("7"))
button8 = Button(frame_bottom, text="8", width="20", height="6", bg=buttonColor, command=buttonEntry("8"))
button9 = Button(frame_bottom, text="9", width="20", height="6", bg=buttonColor, command=buttonEntry("9"))
button0 = Button(frame_bottom, text="0", width="20", height="6", bg=buttonColor, command=buttonEntry("0"))
#function which doesn't execute when button is pressed
def buttonEntry(num):
n=num
print(n)
我希望在按下 button1 时显示 1,在按下 button2 时显示 2,所以,打开。但是当我运行程序时,所有按钮都会同时运行它们的命令并显示如下输出:
1
2
3
4
5
6
7
8
9
0
Process finished with exit code 0
然后按下的按钮不显示任何内容。
【问题讨论】:
标签: python button tkinter tkinter-entry