Bottom Page

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.
Quote
#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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Binding functions in Qt Designerr Mocap 12 606 Aug-22-2019, 03:38 PM
Last Post: Denni
  Binding functions to Menus in tkinter?? Mocap 1 219 Jul-23-2019, 01:37 AM
Last Post: Larz60+
  [Tkinter] how to get the entry information using Entry.get() ? SamyPyth 2 628 Mar-18-2019, 05:36 PM
Last Post: woooee
  [Kivy] Kivy property (in .kv) loses binding to a variable (in .py) j.crater 3 1,375 Aug-14-2018, 12:37 PM
Last Post: buran

Forum Jump:


Users browsing this thread: 1 Guest(s)