When the window is resized, I want the height to be set equal to the width so the windows always is a square. In the code below print(event.width) does print the new window width, but canvas.configure(height=event.width) doesn't change the canvas height. What am I doing wrong?
EDIT: I want the whole window to stay squared.
import tkinter as tk
from timeit import default_timer as timer
start_timer = timer()
height = 600
width = 600
red = ("#ff7663")
root = tk.Tk()
canvas = tk.Canvas(root, height=height, width=width, background=red)
canvas.pack(expand=True,fill="both")
def resize(event):
end_timer = timer()
if end_timer - start_timer > 0.5:
print(event.width)
canvas.configure(height=event.width)
canvas.bind("<Configure>", resize)
root.mainloop()```
rootwindow:root.bind("<Configure>", resize). But to be honest I'm not sure I understand what issue you're having. When Icanvas.pack(expand=True,fill="both"), the canvas automatically takes up the whole root window regardless of its initialwidthorheight, and fills the window on resize. Do you want the canvas to be square even when the root window isn't?root.wm_aspect(i.e.,tk.aspect), but apparently it doesn't work...I'm at a loss, I'm afraid.