Home > Enterprise >  Tkinter: how to set a buttons position relative to the screen
Tkinter: how to set a buttons position relative to the screen

Time:11-21

from tkinter import *

Window = Tk()
Window.attributes('-fullscreen', True)

b1 = Button(Window, text="1", activeforeground="black", activebackground="gray", pady=2,
            font='secular_one', relief=GROOVE)
b1.place(x=1100, y=50)

b2 = Button(Window, text="2", activeforeground="black", activebackground="gray", pady=2,
            font='secular_one', relief=GROOVE)
b2.place(x=1100, y=220)

b3 = Button(Window, text="3", activeforeground="black", activebackground="gray", pady=2,
            font='secular_one', relief=GROOVE)
b3.place(x=1100, y=380)

Window.mainloop()

I`m making an app that uses Tkinter and I want to place some buttons in a certain position so after I did that using .place I went to work at another computer but the buttons were in the middle of the screen instead of where I placed them originally

CodePudding user response:

The kwargs xand y for place define the widget absolute position in pixels. So if you run the program on a display with a different resolution, it won't look the same.

Try to define relative positions instead:

b1.place(relx=0.3, rely=0.1)
  • Related