Python Forum
TkInter Binding Buttons
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TkInter Binding Buttons
#3
(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()
Reply


Messages In This Thread
TkInter Binding Buttons - by ifigazsi - Apr-04-2020, 05:10 PM
RE: TkInter Binding Buttons - by deanhystad - Apr-04-2020, 07:20 PM
RE: TkInter Binding Buttons - by ifigazsi - Apr-05-2020, 10:47 AM
RE: TkInter Binding Buttons - by ifigazsi - Apr-05-2020, 07:03 PM
RE: TkInter Binding Buttons - by deanhystad - Apr-06-2020, 04:36 AM
RE: TkInter Binding Buttons - by ifigazsi - Apr-06-2020, 08:30 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Key Binding scope angus1964 1 1,300 Jun-30-2022, 08:17 PM
Last Post: deanhystad
  tkinter toggle buttons not working Nu2Python 26 7,543 Jan-23-2022, 06:49 PM
Last Post: Nu2Python
  kivy binding issue hammer 8 3,200 Nov-07-2021, 11:34 PM
Last Post: hammer
  [Tkinter] binding versus disable DPaul 6 7,093 May-05-2021, 05:17 PM
Last Post: DPaul
  [Tkinter] Binding Entry box to <Button-3> created in for loop iconit 5 5,121 Apr-22-2020, 05:47 AM
Last Post: iconit
  Making text clickable with binding DT2000 10 5,385 Apr-02-2020, 10:11 PM
Last Post: DT2000
  Issue on tkinter with buttons Reldaing 1 2,507 Jan-07-2020, 08:21 AM
Last Post: berckut72
  Need tkinter help with clicking buttons pythonprogrammer 2 2,550 Jan-03-2020, 04:43 AM
Last Post: joe_momma
  [Tkinter] Setting Binding to Entry created with a loop? p_hobbs 1 2,133 Nov-25-2019, 10:29 AM
Last Post: Larz60+
  Tkinter Buttons action d3fi 1 2,070 Nov-20-2019, 09:16 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020