I created a simple GUI but every time I click one of the buttons, the GUI flickers. I looked at some other SO questions but none were abstract enough to help me solve my particular problem.
This is the code I'm working with (I know it's a lot of code but I thought any little detail could be the cause of the issue):
import tkinter as tk
class LeftMenu:
def __init__(self, master):
def call_home():
h = Home(master)
h.__init__(master)
def call_overviews():
h = Overviews(master)
h.__init__(master)
self.maincolor = 'darkgrey'
self.menucolor = 'grey'
# Menu creation
menu = tk.Frame(master, bg=self.menucolor)
# def quitcurrent():
# menu.quit()
# Menu positioning
menu.grid(row=0, column=0, sticky='nsew')
# Menu items
self.home = tk.Button(menu, text='Home', command=lambda: [call_home()])
self.overview = tk.Button(menu, text='Overview', command=lambda: [call_overviews()])
# Menu items location
self.home.grid(row=0, column=0, pady=(25, 50), padx=15)
self.overview.grid(row=1, column=0, pady=(0, 50), padx=15)
# Menu items configuration
buttons = [self.home, self.overview]
for self.button in buttons:
self.button.configure(width=20, height=5, highlightbackground=self.menucolor)
class Home(LeftMenu):
def __init__(self, master):
super().__init__(master)
self.homeright(master)
def homeright(self, master):
# Main creation
main = tk.Frame(master, bg=self.maincolor)
# Main positioning
main.grid(row=0, column=1, sticky='nsew')
# Main items
self.maintext = tk.Label(main, text='Welcome to the Apartment Manager', bg=self.maincolor, pady=250)
self.maintext.pack()
class Overviews(LeftMenu):
def __init__(self, master):
super().__init__(master)
self.homeright(master)
def homeright(self, master):
# Main creation
main = tk.Frame(master, bg=self.maincolor)
# Main positioning
main.grid(row=0, column=1, sticky='nsew')
# Main items
self.maintext = tk.Label(main, text='It actually worked', bg=self.maincolor, pady=250)
self.maintext.pack()
root = tk.Tk()
root.title('Apartment Manager')
root.geometry('750x750')
root.grid_columnconfigure(0, weight=1)
root.grid_columnconfigure(1, weight=7)
root.grid_rowconfigure(0, weight=1)
root.wm_withdraw()
root.update()
runit = Home(root)
root.after(1, root.deiconify)
root.mainloop()
I thought it might have to do something with the lines:
root.wm_withdraw()
root.update()
root.after(1, root.deiconify)
So I ran it without those lines, but it had no effect. Does anyone know what is causing the GUI to flicker every time I click on one of the buttons and how to solve it?
Using Python 3.8 and tkinter 8.6