Python Forum
[Tkinter] Setting Binding to Entry created with a loop?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Setting Binding to Entry created with a loop?
#1
I'm not even really sure what to google to find what I'm looking for. So I haven't been able to find what I'm looking for.

So, I'm creating a series of Entry widgets using a loop.

    def efs_widgets(self):
        elems = ['Cu',
                 'Fe',
                 'S',
                 'SiO2',
                 'CaO',
                 'Al2O3',
                 'Fe3O4']
        row_count = 4
        for i in range(len(elems)):
            self.tb = "efs_" + elems[i] + "_Box"
            self.tb = Entry(self.frame2, width=18, bg="#E6EAEC")

            if (i%2)==0:
                self.tb.grid(row=row_count, column=1, padx=1, pady=5)                
            else:
                self.tb.grid(row=row_count, column=4, padx=1, pady=5)
                row_count = row_count+1
Then when I try to set a binding to the entry widget I get an error saying that there is no attribute

    def efs_form(self):
        def chb_click(event):
    
            self.avg_string = ""
            self.in_avg = ""
            if self.chb_var == 1:
                self.chb_var = 0
                self.avg_string = "NOT included in the Average."
                print(self.avg_string)
            else:
                self.chb_var = 1
                self.avg_string = "Included in the Average."
                self.in_avg = "X"
                print(self.avg_string)

        self.reset_form()
        self.efs_btn["bg"]='Red'
        self.db_conn = sqlite3.connect('EFS_Samples.db')
        self.c = self.db_conn.cursor()
        self.chb_var = 1
        self.next_box = True
        # Create Database Table
        self.c.execute(""" CREATE TABLE IF NOT EXISTS efs(
            _Timestamp text,
            Arrival_Time text,
            Sample_Time text,
            analyst text,
            cro text,
            cu text,
            fe text,
            s text,
            si text,
            ca text,
            al text,
            mag text,
            avg text        
            )""")
        self.efs_widgets()
        
        self.c.execute("SELECT * FROM efs")
        self.prev_sams = self.c.fetchmany(20) 
        
        self.efs_prev_lb.delete(0, END)
        self.efs_analyst_lb.delete(0, END)
        self.efs_cu_lb.delete(0, END)
        self.efs_avg_lb.delete(0, END)
        
        for sam in self.prev_sams:
            self.efs_prev_lb.insert(0, sam[2])
            self.efs_analyst_lb.insert(0, sam[3])
            self.efs_cu_lb.insert(0, sam[5])
            self.efs_avg_lb.insert(0, sam[12])
        
        self.efs_Cu_Box = ""
  
  #THIS IS WHERE I NEED THE HELP    
        #Events
        self.efs_arr_Time.bind("<FocusIn>", self.focus_in)
        self.efs_sam_Time.bind("<FocusIn>", self.focus_in)
        self.efs_analyst.bind("<<ComboboxSelected>>", self.focus_in)
        self.efs_cro.bind("<<ComboboxSelected>>", self.focus_in)
        self.efs_Cu_Box.bind("<FocusIn>", self.focus_in)
        self.efs_Fe_Box.bind("<FocusIn>", self.focus_in)
        self.efs_S_Box.Bind("<FocusIn>", self.focus_in)
        self.efs_SiO2_Box.Bind("<FocusIn>", self.focus_in)
        self.efs_CaO_Box.Bind("<FocusIn>", self.focus_in)
        self.efs_Al2O3_Box.Bind("<FocusIn>", self.focus_in)
        self.efs_Fe3O4_Box.Bind("<FocusIn>", self.focus_in)
        self.efs_avg_chb.bind("<Button-1>", chb_click)
        
        self.db_conn.commit()
        self.c.close()
        self.db_conn.close()
Can I get some help how I can approach this? Thanks. It would be much appreciated.
Reply
#2
Quote:I get an error saying that there is no attribute
Please always post the error traceback, complete and unaltered, it contains valuable information that shows what led up to the error.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Key Binding scope angus1964 1 1,168 Jun-30-2022, 08:17 PM
Last Post: deanhystad
  kivy binding issue hammer 8 2,937 Nov-07-2021, 11:34 PM
Last Post: hammer
  [Tkinter] define entry via class on a loop drSlump 9 3,373 Oct-27-2021, 05:01 PM
Last Post: deanhystad
  [Tkinter] binding versus disable DPaul 6 6,594 May-05-2021, 05:17 PM
Last Post: DPaul
  [Tkinter] Binding Entry box to <Button-3> created in for loop iconit 5 4,874 Apr-22-2020, 05:47 AM
Last Post: iconit
  TkInter Binding Buttons ifigazsi 5 4,160 Apr-06-2020, 08:30 AM
Last Post: ifigazsi
  Making text clickable with binding DT2000 10 5,028 Apr-02-2020, 10:11 PM
Last Post: DT2000
  Problem with setting variable within a Entry validatecommand kenwatts275 1 1,849 Mar-31-2020, 01:53 AM
Last Post: deanhystad
  Transfer Toplevel window entry to root window entry with TKinter HBH 0 4,420 Jan-23-2020, 09:00 PM
Last Post: HBH
  Binding functions in Qt Designerr Mocap 12 5,784 Aug-22-2019, 03:38 PM
Last Post: Denni

Forum Jump:

User Panel Messages

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