Reputation: 87
why do i get this error? this is my first time trying to understand what is going in a class but i cant seem to figure it out. the app variable saves it as tkinter windowframe and that way i can put widgets on it but if i need to change the geometry how would i do this?. im sorry for my bad explaining. Any help would do.
import tkinter as tk
class App(tk.Frame):
def __init__(self, parent):
app = tk.Frame.__init__(self, parent)
self.button = tk.Button(app, text="start")
self.button.pack()
app.geometry("500x400")
if __name__ == "__main__":
app1 = tk.Tk()
App(app1)
app1.mainloop()
Upvotes: 1
Views: 435
Reputation: 2169
When you pass a parameter to class constructor, simply assign it to an instance property (by typing self.instanceProperty = whatYouPassed
), then you can work on it.
import tkinter as tk
class App:
def __init__(self, parent):
self.app = parent
self.app.geometry("500x400")
self.button = tk.Button(self.app, text="start")
self.button.pack()
if __name__ == "__main__":
app1 = tk.Tk()
App(app1)
app1.mainloop()
Reading doc about classes might be useful.
Upvotes: 1