Tkinter recursion error when calling update several times

64 Views Asked by At

I want to create a frameless resizable window, the problem is, when there are many widgets, they glitch when the window is resized using a Sizegrip. The only solution that I found that removes this glitch effect is to update the window during the resize. Unfortunately if you keep resizing for a few seconds a recursion error will occur and I have no idea why.

Here's my code

import tkinter as tk
from tkinter.ttk import Sizegrip


root = tk.Tk()
root.overrideredirect(True)
root.geometry("500x400")


def on_resize(event):
    global root
    root.update()



tk.Label(root, text = "Use the bottom right grip to resize, try for a few seconds").pack()

sg = Sizegrip(root)
sg.pack(side = tk.BOTTOM, anchor = tk.E)

sg.bind("<B1-Motion>", on_resize)

root.mainloop()
1

There are 1 best solutions below

0
On

Check if you're already resizing and don't call root.update() again.

resizing = False

def on_resize(event):
    global resizing
    if not resizing:
        resizing = True
        root.update()
        resizing = False