samedi 9 janvier 2021

tkinter variable not returning value from function call - Object has no attribute

I am very noob and learning python whilst locked down. My background is VB so very different at times.

Within the init of a class called Main I set up a checkbox

    var1 = tk.BooleanVar()
    var1.set = True
    Date_checkbox = tk.Checkbutton(master, text="All dates?",
                                   variable=var1).grid(row=7, sticky=tk.W)

In the class I have a fuction thus:

def use_all_the_daterange(self):
    return self.var1.get()

I have a button I press which calls this function but I get AttributeError: 'Main' object has no attribute 'var1'on the function above.

I don't get this. Within the init function I can happily access var1, but not within this other function in the same class. Is this something to do with variable scope? Any clues. I am very new to python and still learning lots.




Aucun commentaire:

Enregistrer un commentaire