Python Forum
[Tkinter] Binding Entry box to <Button-3> created in for loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Binding Entry box to <Button-3> created in for loop
#2
This part of Your code:
        Entry(r_frm, bd=1, relief='solid', justify='center', width=4).grid(row=r, column=c)
        Entry.bind('<Button-3>', call_top)
the Entry widget does not have a name, therefore the bind statement Entry.bind('<Button-3>', call_top)
is trying to bind Tkinter's 'Entry' object, not your widget.

With entries in a loop like this,
create a list or dictionary prior to entering loop, and append each entry to the list, add the binding to each element as appended.
If you use a dictionary, you can append a key to each entry which will aid you if you need to change the configuration for an individual entry some time in the future.

Example (this for buttons, but concept is the same):
self.buttons = {}

for name in ['A', 'B', 'C']:
            self.buttons[name] = {}
            self.buttons[name]['name'] = name
            self.buttons[name]['button'] =  tk.Button(self.f2, fg="green", text=f"Solve for {name}")
            self.buttons[name]['button'].bind('<Button-1>', lambda event, bname=self.buttons[name]['name']: self.solve_equation(event, bname))
            self.buttons[name]['button'].pack(side=tk.LEFT)
Reply


Messages In This Thread
RE: Binding Entry box to <Button-3> created in for loop - by Larz60+ - Apr-21-2020, 01:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Key Binding scope angus1964 1 1,248 Jun-30-2022, 08:17 PM
Last Post: deanhystad
  kivy binding issue hammer 8 3,123 Nov-07-2021, 11:34 PM
Last Post: hammer
  [Tkinter] define entry via class on a loop drSlump 9 3,525 Oct-27-2021, 05:01 PM
Last Post: deanhystad
  [Tkinter] How to terminate a loop in python with button in GUI Joni_Engr 6 11,227 Sep-09-2021, 06:33 PM
Last Post: deanhystad
  [Tkinter] binding versus disable DPaul 6 6,901 May-05-2021, 05:17 PM
Last Post: DPaul
  [PyQt] Loop triggered by button help Purple0 1 2,359 May-17-2020, 02:57 AM
Last Post: deanhystad
  TkInter Binding Buttons ifigazsi 5 4,608 Apr-06-2020, 08:30 AM
Last Post: ifigazsi
  Making text clickable with binding DT2000 10 5,230 Apr-02-2020, 10:11 PM
Last Post: DT2000
  Transfer Toplevel window entry to root window entry with TKinter HBH 0 4,507 Jan-23-2020, 09:00 PM
Last Post: HBH
  [Tkinter] Setting Binding to Entry created with a loop? p_hobbs 1 2,100 Nov-25-2019, 10:29 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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