My application after few random clicks on the buttons starts slowing down drastically and sometimes the labels and buttons disappear completely and the GUI freezes (except the "X" button, it just destroys the program, which is intentional).
My guess would be that the way I want to clear the window (my clear(self) function) is not the proper way to clear it, since I want the buttons to stay no matter which button you click, everything below them should be cleared.
Or maybe it is my class structure, I have seen tons of other ways to create a tkinter class..., maybe I am missing out on a core thing in my code?
My code so far:
from tkinter import *
class LearnTkinter:
def __init__(self, top):
self.top = top
self.title = top.title("LearnTkinter")
self.configure = top.configure(bg="#d9d9d9", highlightbackground="grey", highlightcolor="darkgrey")
wWidth = top.winfo_reqwidth()
wHeight = top.winfo_reqheight()
x = int(top.winfo_screenwidth() / 2 - (wWidth / 2))
y = int(top.winfo_screenheight() / 3 - (wHeight / 2))
top.geometry(f"+{x}+{y}")
top.minsize(274,520)
self.Kill = Button(top,text="X",bg="#d9d9d9", command = top.destroy).place(height=54,width=72)
self.Infos = Button(top, text="i", bg="#d9d9d9", command=self.info_w).place(relx=0.25,height=54,width=72)
self.Help = Button(top, text="?", bg="#d9d9d9", command=self.help_w).place(relx=0.5,height=54,width=72)
self.Settings = Button(top, text="O", bg="#d9d9d9", command=self.settings_w).place(relx=0.75,height=54,width=72)
self.Frame1 = Frame(top, bg="black", relief="groove", borderwidth="8").place(rely=0.1,relheight=0.202,relwidth=1.004)
def clear(self):
for widget in top.winfo_children():
widget.destroy()
Button(top,text="X", bg="#d9d9d9", command=top.destroy).place(height=54,width=72)
Button(top, text="i", bg="#d9d9d9", command=self.info_w).place(relx=0.25,height=54,width=72)
Button(top, text="?", bg="#d9d9d9", command=self.help_w).place(relx=0.5,height=54,width=72)
Button(top, text="O", bg="#d9d9d9", command=self.settings_w).place(relx=0.75,height=54,width=72)
def info_w(self):
self.clear()
top.title("Info")
Label(top, text="This is going to be the information section ", bg="grey").place(rely=0.1, relwidth=1)
def help_w(self):
self.clear()
top.title("Help")
Label(top, text="This is going to be the help center", bg="grey").place(rely=0.1, relwidth=1)
def settings_w(self):
self.clear()
top.title("Settings")
top = Tk()
exa_gui = LearnTkinter(top)
top.mainloop()
question from:
https://stackoverflow.com/questions/65861785/tkinter-application-crashing-while-clicking-different-buttons