Apr-05-2020, 10:47 AM
(Apr-04-2020, 07:20 PM)deanhystad Wrote: pressed_enter is a function. You can bind a function. pressed_enter() calls the function and is the function's return value (None). You cannot bind None.
Thanks, now it works!
One more:
Is it possible that tk.Button and Key binding use the same function?
import tkinter as tk root = tk.Tk() root.geometry('250x100') ############# FUNCTIONS ###########x def check_in_database_with_btn(data, chk): if data in chk: print(f'{data} was found in database.') else: print(f'{data} no match in database.') def check_in_database_with_key(event, data, chk): check_in_database_with_btn(data, chk) ########### DATABASE ################## chk_database = ['Eric', 'John', 'Graham', 'Terry'] ############ ENTRY & BUTTON & BIND ###################### field_entry = tk.Entry(root, width=20) field_entry.grid(row=0, column=0) chk_in_database_btn = tk.Button(root, text='Check database', command=lambda: check_in_database_with_btn(field_entry.get(), chk_database)) chk_in_database_btn.grid(row=0, column=1) field_entry.bind("<Return>", lambda event: check_in_database_with_key(event, field_entry.get(), chk_database)) root.mainloop()