在tkinter中设置对象坐标



我正在使用tkinter,但无论如何我都找不到设置对象坐标的方法。在python文档中,只提到了使用side。有没有办法说我的物体在窗户里的左边和上面?例如:

import tkinter
from tkinter.constants import *
tk = tkinter.Tk()
frame = tkinter.Frame(tk, relief=RIDGE, borderwidth=2)
frame.pack(fill=BOTH,expand=1)
label = tkinter.Label(frame, text="Hello, World")
label.pack(fill=X, expand=1)
button = tkinter.Button(frame,text="Exit",command=tk.destroy)#here I need to put my button at left=0,top=10 !!!
button.pack(side=BOTTOM)
tk.mainloop()

使用place()代替pack()。但不要在同一Frame中同时使用pack()grid()place()。当然,您可以在父Frame中使用(例如)pack(),在子Frame中使用grid()

请参阅:网格几何管理器、包装几何管理器和放置几何管理器

最新更新