0
在Tkinter中,我怎样才能将画布打包到左上角并将按钮放到右下角?我尝试了can.pack(side=...)
和button.pack(side=....)
,但没有运气。我想得到像这样的Picture。在Tkinter中定位一个画布和一个按钮
在Tkinter中,我怎样才能将画布打包到左上角并将按钮放到右下角?我尝试了can.pack(side=...)
和button.pack(side=....)
,但没有运气。我想得到像这样的Picture。在Tkinter中定位一个画布和一个按钮
你就近了。您需要添加一个选项:anchor
。
下面是一个简单的脚本来演示:
import Tkinter as tk
root = tk.Tk()
canvas = tk.Canvas(bg="red", height=100, width=100)
canvas.pack(anchor=tk.NW)
button = tk.Button(text="button")
button.pack(side=tk.RIGHT, anchor=tk.SE)
root.mainloop()
当你调整窗口的大小,注意画布如何停留在左上角和按钮停留在右下角。