Hey guys i´m new to tkinter and i´m testing stuff out. In this code i´m getting the error "'Graphicaluserinterface' object has no attribute 'var'" which i don´t understand, since i have it in my init method. My Code:
import tkinter as tk class Graphicaluserinterface(tk.Frame): def __init__(self,master=None): super().__init__(master) self.grid() self.create_widgets() self.startbuttonfunktion() self.checkbutton1 self.var=IntVar() def create_widgets(self): self.programmstart = tk.Button(self, text = "Programmstart") self.programmstart.grid(row=0,column=1) self.programmstart["command"]=self.startbuttonfunktion self.programmschliessen = tk.Button(self, text ="Exit Programm",command=root.destroy) self.programmschliessen.grid(row=1,column=2) self.checkbutton1 = tk.Checkbutton(self, text = "Sensoren1",variable=self.var,onvalue=1,offvalue=0) self.checkbutton1.grid(row=1,column=0) def startbuttonfunktion(self): if self.var.get()==1: print("Der Checkbutton wurde geklickt") else: print("Der Checkbutton wurde NICHT geklickt") root = tk.Tk() app = Graphicaluserinterface(master=root) app.master.title("TestProgramm") app.master.maxsize(1200,600) app.mainloop()