I want my function to be executed after the button press. But as I run the program the button calls the function for all the buttons before I click on them. And when I press the button, after my output is showing, none of the buttons work.
Rest of the buttons in the programs are working fine in the same way.
#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)
I want 1 to be displayed when button1 is pressed, 2 to be displayed when button2 is pressed, so, on. But when I run the program, all the buttons run their commands at once and shows the output like:
1
2
3
4
5
6
7
8
9
0
Process finished with exit code 0
And the button pressed afterward doesn't display anything.