Reputation: 2075
I'm trying to place widgets using the .place()
method. I understand that x
and y
are measured from the top left side of the page, but I'm trying to change it, so it can measure it from the top right.
My reason being, I would like the label to always be a constant distance from the right side of the page. I've tried relx
and rely
but unfortunately it didn't work for me, and for some reason neither is the anchor.
Can anyone help with this?
Here's my code:
from tkinter import *
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.geometry('500x500')
root.configure(bg='blue')
label = Label(root,text='Hello',anchor='nw')
label.place(x=50,y=50)
root.mainloop()
Upvotes: 0
Views: 550
Reputation: 1057
Try giving x and y co-ordinates to widgets, something like this,
import tkinter as tk
root=tk.Tk()
root.geometry('300x300')
b1=tk.Button(root,text="b1",width=12)
b1.place(relx = 1, x =-2, y = 2, anchor = 'ne')
b2=tk.Button(root,text="b2",width=12)
b2.place(relx = 1, x =-2, y = 30, anchor = 'ne')
root.mainloop()
hope this helps you!
Upvotes: 2