How to position buttons in Tkinter with Place

Опубликовано: 08 Октябрь 2024
на канале: ActiveState
18,210
43

How to Position Buttons With Place
Place() has two options you can use: x and y

The x variable aligns buttons horizontally.
The y variable aligns buttons vertically.

In this example, place() is used to position buttons based on x,y coordinates in a frame:

import tkinter

master=tkinter.Tk()
master.title("place() method")
master.geometry("450x350")

button1=tkinter.Button(master, text="button1")
button1.place(x=25, y=100)

button2=tkinter.Button(master, text="button2")
button2.place(x=100, y=25)

button3=tkinter.Button(master, text="button3")
button3.place(x=175, y=100)

master.mainloop()

Learn more about Tkinter and other Python packages at https://www.activestate.com/learn-python