I'm trying to make a simple numpad made with guizero in python, where each number has a button, and when the buttons are pressed, they return their number into a text box, where the text box had the PIN entered with the onscreen numpad or by keyboard and check whether the value of the text box is the same as that stored in a variable called pin. The enter button on the numpad will do the same as pressing enter on the keyboard. I have tried a lot of things, but when returning from the function that the button calls, an error throws, or the function would set the text box value without the button being pressed. If someone can send me some edits that does this for me I woukd be very grateful. Numpad layout: 1 2 3 4 5 6 7 8 9 0
Enter
This is the code i have so far (i have only 3 buttons to save visual space, and i know that for all 10 buttons ill have to just duplicate them:
import guizero as gz
global pin
pin = ""
def pressed_1(number):
text_pin.set(number)
def pressed_2(number):
text_pin.set(number)
def pressed_3(number):
text_pin.set(number)
def main():
app = gz.App(title="pin",layout="grid")
global text_pin
text_pin = gz.TextBox(app,text=pin,grid=[0,0])
button_1 = gz.PushButton(app,text="1",command=pressed_1("1"),grid=[1,1])
button_2 = gz.PushButton(app,text="2",command=pressed_2("2"),grid=[2,1])
button_3 = gz.PushButton(app,text="3",command=pressed_3("3"),grid=[3,1])
app.display()
main()
Thank you all