Winfo proposals10/25/2022 ![]() ![]() In first version I rounded values to integers but then object was not ideally in center after few resizes. On my computer it is 8 - I test different values till I get the same values for curr_w/curr_h and new_w,new_h at start. It seems that event gives canvas's size with border or relief so you have to substract some value. Instead of self.winfo_reqwidth(), self.winfo_reqheight() To get current size of canvas you need curr_w = int( self ) WINFO PROPOSALS HOW TOI suspect if I stop the window from resizing, I'd be able to store the center value and update it after moving the object, but I don't know how to do that. If I then shrink the window in any way, the created item is moved strictly up and left. ![]() WINFO PROPOSALS FULLThe slider (or sliders in the full code) does not appear. py script: the window appears, then smoothly expands until the canvas becomes 1920x1080 (my screen resolution). Self.id = canvas.create_line(splitterCoords(canv_w,canv_h), fill = color, tags = "item") Self.move("item",round((new_w-curr_w)/2),round((new_h-curr_h)/2))īg = ResizingCanvas(frame, width = 1200, height = 600, background = "#F0F0F0", borderwidth = 3, relief = SUNKEN)ĭistSliders.pack(fill = X, expand = 1, side = LEFT)ĭistMirror1Obj = Scale(distSliders, orient=HORIZONTAL)ĭistMirror1Obj.pack(fill = X, expand = 1) SplitterLen = round(round(canv_h/5)*0.5*math.sqrt(2)) Using curr_w = self.winfo_width() makes the differences 0. I printed the supposed offsets (differences between new and old size, split in half and rounded), but they are constantly negative, regardless of whether I'm expanding or shrinking the window in either direction. ![]() How to get tkinter canvas to dynamically resize to window width? I used the solution offered here, slightly adjusted by me to move objects instead of rescaling them. I've left in only one slider to show the general idea without too much clutter. two frames that each hold a couple sliders.How do I move all objects on window resize? All of them are tied to the window center. The canvas is currently contained in the GUI. I want each physical object and the GUI to have their own classes for drawing, and I want to be able to resize the window. I'm working on an interactive simulator for physics. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |