有没有办法在窗口中放置画布并在其周围放置一个框架?我只发现如何在画布内放置对象。
问问题
17813 次
3 回答
6
您可以创建一个框架,然后将您的小部件放入其中:
f = tk.Frame(...)
c1 = tk.Canvas(f, ...)
c2 = tk.Canvas(f, ...)
c1.pack(side="left", fill="both", expand=True)
c2.pack(side="right", fill="both", expand=True)
以上将在一个框架内为您提供两个并排的画布。当您调整包含窗口的大小时,它们会增长和缩小。
于 2012-10-29T02:34:03.743 回答
0
您可以使用 place() 函数而不是 pack() 并执行以下操作:
canvas.place(relx=0.5, rely=0.5, anchor=CENTER)
这将把它放在中心。
于 2019-01-31T17:31:49.040 回答
0
Like fortyTwo102 mentioned, the place
function will allow you to specify exactly where the canvas is. I thought I'd provide some more examples:
# in the center
canvas.place(relx=0.5, rely=0.5, anchor=CENTER)
# in the bottom right corner
canvas.place(relx=1.0, rely=1.0, anchor=SE)
# in the bottom left corner
canvas.place(relx=0.0, rely=1.0, anchor=SW)
# 30 pixels from the left, 50 from the top
canvas.place(x=30, y=50)
Source (and more helpful info): https://www.tutorialspoint.com/python/tk_place.htm
于 2020-08-18T00:05:17.587 回答