Aug-04-2022, 04:15 AM
(This post was last modified: Aug-04-2022, 04:15 AM by Gribouillis.)
When you bind the callback to a key, it receives a KeyPress event parameter every time the key is pressed. On the other hand, a function bound to a Button does not receive a parameter when the button is pressed. So if you want to bind the callbacks both to a key and to a Button, you need to give them a variable number of arguments. Try adding a
print()
in the functions to see what it does# Change text with "Enter" then flush def changeTextEnter(*args): print('changeTextEnter:', args) text_label.configure(text=entry_bar.get()) entry_bar.delete(0, tk.END) # Close program key function def quitApp(*args): print('quit:', args) main_window.destroy()
Output:changeTextEnter: (<KeyPress event keysym=Return keycode=36 char='\r' x=89 y=14>,)
changeTextEnter: ()
quit: (<KeyPress event keysym=Escape keycode=9 char='\x1b' x=181 y=14>,)