Feb-20-2022, 10:22 PM
(This post was last modified: Mar-14-2022, 07:15 PM by deanhystad.)
I'm starting to like making an App class for the root window.
import tkinter as tk class MainWindow(tk.Tk): """Root window class""" def __init__(self, *args, title="Example", **kwargs): super().__init__(*args, **kwargs) if title: self.title(title) self.label = tk.IntVar(value=0) tk.Label(self, textvariable=self.label).pack() tk.Button(self, text='Press Me', command=self.change, width=30).pack(padx=5, pady=5) def change(self): self.label.set(self.label.get() + 1) def main(): app = MainWindow() app.mainloop() if __name__ == '__main__': main()Or skip making a main().
if __name__ == '__main__': MainWindow().mainloop()