-2

Having trouble passing bind function to another function. Multiple Combobox instances. On election. Change entry. Combobox not passing function to required function.

class Application(tk.Frame):

    def __init__(self, *args, **kwargs):
        tk.Frame.__init__(self)
        self.ChkOut01
        self.UpdateDia
        self.UpdateDia01

    def ChkOut01(self):
        ent_dia_d01 = ttk.Combobox(root, width=10, justify=tk.CENTER)
        ent_dia_d01 ['values'] = (" 0.38 - 0.885"," 0.50 - 1.165", \
                                  " 0.75 - 1.405"," 1.00 - 1.780", \
                                  " 1.25 - 2.270"," 1.50 - 2.525", \
                                  " 2.00 - 3.040")
        ent_dia_d01.bind('<<ComboboxSelected>>', self.UpdateDia01)

    def UpdateDia(self):
        ent_dia_d = 'ent_dia_d' + self.n
        if globals()[ent_dia_d].get() == " 0.38 - 0.885":
            globals()[ent_dia_d].delete(0, 'end')
            globals()[ent_dia_d].insert(0, ("0.885"))

    @staticmethod
    def UpdateDia01(self):
        self.n = 01
        self.UpdateDia()
        return self.n

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
niro
  • 1
  • 4
  • Remove the decorator `@staticmethod` and read up on [Events and Bindings](http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm) – stovfl Mar 21 '20 at 01:20
  • Hi thanks. removing decorator TypeError: UpdateDia01() takes 1 positional argument but 2 were given – niro Mar 21 '20 at 01:56
  • There is absolutely no reason to use something like `globals()[ent_dia_d]`. There's nothing you can do with that which you can't do more easily with just a normal dictionary. – Bryan Oakley Mar 21 '20 at 04:02
  • @Bryan that's what they say. I don't know the tool box. Change of profession Bryan. This is what I know. Agreed not too much. Other hand if I were to drop a 5k piece of inconel on your workbench... no backspaces and looking in the clouds for answers allowed. Bryan kindly instruct how the professionals work. – niro Mar 21 '20 at 04:58
  • @niro ***"TypeError: UpdateDia01() ..."*** That's explained in this answer [Getting the selected value from combobox](https://stackoverflow.com/a/31265689/7414759) – stovfl Mar 21 '20 at 09:19

1 Answers1

0
class Application(tk.Frame):

    def __init__(self, *args, **kwargs):
        tk.Frame.__init__(self)
        self.UpdateDia
        self.UpdateDia01

    def ChkOut01(self):
        self.row_psn = self.row_000 + (self.row_inc*1)        
        global ent_dia_d01
        ent_dia_d01 = tk.StringVar()
        ent_dia_d01 = ttk.Combobox(root, width=self.col_ent, justify=tk.CENTER)
        ent_dia_d01 ['values'] = (" 0.38 - 0.885"," 0.50 - 1.165", \
                                  " 0.75 - 1.405"," 1.00 - 1.780", \
                                  " 1.25 - 2.270"," 1.50 - 2.525", \
                                  " 2.00 - 3.040")
        ent_dia_d01.bind('<<ComboboxSelected>>', self.UpdateDia01)
        ent_dia_d01.place(x=self.row_dia, y=self.row_psn-2)
        ent_dia_d01.insert(0, (ins_prj_dia))

    def UpdateDia(self, *args):
        ent_dia_d = 'ent_dia_d' + self.n
        if globals()[ent_dia_d].get() == " 0.38 - 0.885":
            globals()[ent_dia_d].delete(0, 'end')
            globals()[ent_dia_d].insert(0, ("0.885"))
        # continued

    def UpdateDia01(self, *args):
        self.n = '01'
        self.UpdateDia(self)
        return self.n
    # continued
niro
  • 1
  • 4