Reputation: 45
how I can set position of label using .pack()?
I want make something such this:
Label(root, text ="Text").pack(x=100, y=100)
Upvotes: 2
Views: 4903
Reputation: 332
you can it with side=left/right/bottom/top
but in some situation you need to change your widets positon or you can use before or after
in the pack-manager
. in some situations, the place-manager
is maybe better, if you want specific postions
from tkinter import *
root = Tk()
root.geometry("700x700")
frame1 = Frame(root, bg="blue")
frame1.pack(fill="x", pady=20, ipady=20) # fill = x, y or "both" // pady = down from the titlebar // ipady or ipadx =
# = the height of a widget
frame2 = Frame(root, bg="red")
frame2.pack(side="left", fill="y", ipadx=20) # side = left, top, bottom, right // there also an expand function, that you can
# use it with expand=true/false, expand="yes"/"no" etc....
mainloop()
Upvotes: 0
Reputation: 140
pack() is only designed to organize geometry vertically. It looks like you're looking for grid() and/or setting object sizes carefully when making the objects. If you're dead-set on using pack(), you can pack a frame and grid objects within it.
Upvotes: 0
Reputation: 34
.pack()
method does not set position for any tkinter object , use .grid()
with the arguments bieng (row=,column=
).
this will help you set the position of an object
Upvotes: 2