(tkinter) I want to catch window width and height immediately after resizing. How could I do that, is any methods existing?
Edited question:
deets, It is not a duplicate. Because in the link there is canvas, and this method
self.scale("all",0,0,wscale,hscale)
is not working for Frame. I still doesn't know how to resize frame so it would had the same width and height as the window after I resize it. (Like in photoshop, I resize the window and background is changing sizes).
Bryan, I tried to resize with as you said, but it doesn't work. I tagged where I tried to do it with '!!!' comment. My code:
from tkinter import *
import ctypes
class Main(Frame):
def __init__(self, main):
Frame.__init__(self, main)
# Vars that will be defined by user:
self.canvas_width = 600
self.canvas_height = 600
self.frame_width = 750
self.frame_height = 600
# Flexible widgets when window size alters:
main.columnconfigure(0, weight=1)
main.rowconfigure(0, weight=1)
# Canvas and frame
self.canvas_frame = Frame(main, width=self.frame_width, height=self.frame_height, relief='groove')
self.canvas_frame.grid(row=1, column=1)
self.canvas_frame.grid_propagate(False)
self.canvas = Canvas(self.canvas_frame, width = self.canvas_width, height = self.canvas_height,
bg='bisque')
self.canvas.grid(row=0, column=0)
# Right click menu
self.rmenu = Menu(self.canvas_frame, tearoff=0, takefocus=0)
self.rmenu.add_command(label='Add', command=self.hello)
self.canvas.bind("<ButtonPress-3>", self.popup)
# Bind
self.canvas.bind("<ButtonPress-1>", self.scroll_start)
self.canvas.bind("<B1-Motion>", self.scroll_move)
self.canvas_frame.bind("<Configure>", self.on_resize) # !!!!
# resizing window:
def on_resize(self, event): # !!!!
# determine the ratio of old width/height to new width/height
self.canvas_frame.width = event.width
self.canvas_frame.height = event.height
# resize the canvas
self.canvas_frame.config(width=self.canvas_frame.width, height=self.canvas_frame.height)
print(self.canvas_frame.width) # return the same height and width
print(self.canvas_frame.height) # after resizing
if __name__ == '__main__':
main = Tk()
Main(main)
main.mainloop()