Repeated Code not working after 3 uses (Tkinter, Python) (def and invoke)

31 views Asked by At

I'm trying to make a visual keypad, 3x3, 1-9 input.

I'm doing this by using bind , with invoke, and then changing the visuals.

so far, this is my code:

# for righBox


def invoke7(event):
    sevenButton.config(relief="sunken")
    sevenButton.update_idletasks()
    sevenButton.invoke()
    root.after(100, sevenButton.config(relief="raised"))
def invoke8(event):
    eightButton.config(relief="sunken")
    eightButton.update_idletasks()
    eightButton.invoke()
    root.after(100, eightButton.config(relief="raised"))
def invoke9(event):
    nineButton.config(relief="sunken")
    nineButton.update_idletasks()
    nineButton.invoke()
    root.after(100, nineButton.config(relief="raised"))

def invoke4(event):
    fourButton.config(relief="sunken")
    fourButton.update_idletasks()
    fourButton.invoke()
    root.after(100, fourButton.config(relief="raised"))

sevenButton = Button(righBox, text="seven", font=(buttonFont), bg=UIBackgroundSecondary, fg="White", borderwidth=4)
root.bind("<7>", invoke7)
eightButton = Button(righBox, text="eight", font=(buttonFont), bg=UIBackgroundSecondary, fg="White", borderwidth=4)
root.bind("<8>", invoke8)
nineButton = Button(righBox, text="nine", font=(buttonFont), bg=UIBackgroundSecondary, fg="White", borderwidth=4)
root.bind("<9>", invoke9)
fourButton = Button(righBox, text="four", font=(buttonFont), bg=UIBackgroundSecondary, fg="White", borderwidth=4)
root.bind("<4>", invoke4)

The first row, 7-8-9, work fine. The next row, 4, just doesn't work. I've tried adding in the whole keypad, and only 7-8-9 ever worked.

I've been staring at this code too long and don't understand python nor tkinter enough to figure this out by myself, so I'm asking here.

Tried the above code, didn't work. I've then tried deleting all lines apart from the 7-8-9 code, and then copy/pasting it and changing the numbers to the corresponding ones on the keypad

def invoke9(event):
    nineButton.config(relief="sunken")
    nineButton.update_idletasks()
    nineButton.invoke()
    root.after(100, nineButton.config(relief="raised"))

becoming

def invoke1(event):
    oneButton.config(relief="sunken")
    oneButton.update_idletasks()
    oneButton.invoke()
    root.after(100, oneButton.config(relief="raised"))

and so on and so forth. Didn't work.

0

There are 0 answers