Tkinter's root window recreates automatically after calling root.resizable()

55 Views Asked by At

Root window 'rebuilds' after calling root.resizable. This cause visual glitch, in which window looks like it was minimized and instantly normalized in around 100 msec.

I tried to use withdraw + deiconify (like here: Tkinter, Flashing Window after calling "wm_iconbitmap" and "resizable"), but it didn't help.

There is a minimalistic example and it's glitch recording: https://youtu.be/4tFhI0TOyNE

import tkinter as tk


def hide_1():
    #root.withdraw()
    root.resizable(True, True)  # enabling this line causes window 'blink'
    frame1.pack_forget()
    frame2.pack(expand=True) 
    #root.deiconify()


def hide_2():
    #root.withdraw()
    root.resizable(False, False)    # enabling this line causes window 'blink'
    frame2.pack_forget()
    frame1.pack(expand=True)
    #root.deiconify()


root = tk.Tk()
root.minsize(width=200, height=200)

frame1 = tk.Frame(root)
btn1 = tk.Button(frame1, text='hide frame1, show frame2', command=lambda: hide_1())
btn1.pack()
frame1.pack(expand=True)

frame2 = tk.Frame(root)
btn2 = tk.Button(frame2, text='hide frame2, show frame1',  command=lambda: hide_2())
btn2.pack()

root.mainloop()

UPD: There is the most minimalistic example. No pack_forget() or withdraw() or deiconify() calling. Just raw root.resizable() call.

import tkinter as tk


root = tk.Tk()
root.minsize(width=200, height=200)

btn1 = tk.Button(root, text='Resize_Off', command=lambda: root.resizable(False, False))
btn1.pack()

btn2 = tk.Button(root, text='Resize_On',  command=lambda: root.resizable(True, True))
btn2.pack()

root.mainloop()
1

There are 1 best solutions below

5
Bryan Oakley On

Tkinter is behaving as designed. You're explicitly withdrawing the window and then causing it to be redisplayed. If you don't want the visual artifact, remove the calls to root.withdraw()

This appears to be a quirk on whatever platform you're running on. I don't see any flicker when I run your code on my Mac.