Lesson-10: Tkinter Place Geometry Manager
Tkinter Place Geometry Manager
This geometry Manager allows us to make more precise tool placement than pack and grid geometry managers. Although it is a bit of a hassle, it can place our widgets in the window more regularly. Now let’s take a look at the way this manager works.
Height: the height of the tool in pixels.
Width: the width of the tool in pixels.
Relheight ( )
Relheight: the height of the vehicle, but at the ratio of the current window height. As an example, relheigth=0.5 the height of the vehicle is half that of the claw. Here it should be noted that when we change the size of the window, the size of this tool automatically decreases or increases at the rate of relheight. A decimal value from 0 to 1 must be included in the parentheses.
btn3 = Button(root, text="BTN3")
btn3.place(relheight=0.6)
the btn3 button will have a height of 0.6 percent of the height of the pop-up window. If the window size changes, the height of the button will also change according to this ratio.
Relwidth ( )
Relwidth: the width of the tool, but at the ratio of the current window width. As an example, if relwidth =0.5, the width of the vehicle is half the width of the claw. Here it should be noted that when we change the size of the window, the size of this tool automatically decreases or increases at the relwidth rate. A decimal value from 0 to 1 must be included in the parentheses.
btn4= Button(root, text="BTN4")
btn4.place(relwidth=0.2)
relx , rely :
relx and rely rate where the left corner of the car will be relative to the window based on the x and y coordinates. The values to be written in parentheses are proportional to the window size and reveal where the tool will be placed. if the value is not entered, it is considered zero.
btn5=Button(root, text="BTN5")
btn5.place(relx=0.3)
btn6=Button(root, text="BTN6")
btn6.place(rely=0.7)
In the above example, the btn5 button also occurs on the left side of the ratio 0.3 times the width of the window x. The btn6 button starts from the Y axis at 0.7 times the y width of the window. If the window size is changed manually, the buttons will change because these values will also change. In the following example, you will understand these values better.
EXAMPLE:
from tkinter import *
root = Tk()
root.geometry("500x500")
btn1 = Button(root, text="BTN1")
btn1.place(height=50, x=200, y=200)
btn2= Button(root, text="BTN2")
btn2.place(width=60, x=300, y=300)
btn3 = Button(root, text="BTN3")
btn3.place(relheight=0.6)
btn4= Button(root, text="BTN4")
btn4.place(relwidth=0.2)
btn5=Button(root, text="BTN5")
btn5.place(relx=0.3)
btn6=Button(root, text="BTN6")
btn6.place(rely=0.7)
mainloop()
In this example, the tkinter module does not receive as jewelry because it is imported using the from tkinter import * command and does not receive tk in front of any tool. it was not placed. You can do it this way too. But this method takes up a lot of memory and can cause problems. Now let’s move on to the code, we’ll go through the name of the button.
The BTN1 and BTN2 buttons are defined in the normal X and y coordinates. When the window is sized, its location will not change.
BTN 3 will start at 0,0 coordinates because the value is not entered. But the relheigth has been entered, and its height will be 0.3 times higher than the current window height. BTN 4 also acts with the same logic.
Only the relx value of BTN5 was entered. Then y will be si o and the window will start to the right of the X axis at about 0.3 percent.
If BTN6, rely 0.7 was entered. If it was 1, the window would have a button y long, so the window would also fill the Y axis. Since it is 0.7, it will have a length of 0.7 times the length of the window y and will start from x 0.
Now let’s examine the screenshot below.
