I don't know if it's a duplicate question or not but I really want to be able to resize placed tkinter widgets when window is resized using .place() only. I know that I can use .grid() for this but to me grid() is confusing, place() seems easy because you just have to give it coordinate and it would place widgets right there. I know that its tough but I really wanna see how to do it.
import tkinter as tk
root = tk.Tk()
button = tk.Button(root, text="Hello")
button.place(x=50, y=50)
root.mainloop()
placeis the wrong tool for the job if you're trying to create a complex responsive UI. Bothpackandgridare much easier because they do all of the work of resizing for you.That being said, if you insist on using
placeand you want the widgets to resize with the window, you need to use relative placement and/or relative sizes.placesupports the following keyword arguments:relx,relyrepresents relative x,y coordinates, where 0 represents the left edge and 1.0 represents the right edge. The values .5,.5 represent the center of the containing widget.relwidth,relheightrepresents the relative width or height of a widget compared to its container. For example, to make a label be the full width of the window it is in you can use arelwidthof 1.0. Arelwidthof .5 would make it half as wide, etc.x,yrepresent absolute positions, or an additional number of pixels added to or subtracted from the relative coordinates. For example,relx=.5, x=5means five pixels to the right of the middle of the containing widget.width,heightrepresent an absolute width or height.anchordefines what part of the widget should appear at the given coordinate.For example, if you wanted to place a frame at the top of the window and have it extend the full width of the window, you might specify it like so:
If you wanted a button placed in the bottom-right of a widget, with a margin of 10 pixels to the right and below, you might do it like this:
Here is an example with those two examples in a window. Notice how they keep their position when you manually resize the window.