有没有一种方法可以将画布放置在窗口中并在其周围添加一个框架?我只找到了如何定位画布内部对象的方法。
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)
canvas.place(relx=0.5, rely=0.5, anchor=CENTER)
这将把它放在中心位置。
place
函数可以让你精确指定画布的位置。我想再提供一些例子:# 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)
Frame
并将该帧对象用作Canvas
的主控件即可。有什么问题吗? - Joel Cornettgrid()
还是pack()
作为你的布局管理器? - Joel Cornettcanvas1.pack(side=LEFT)
和canvas2.pack(side=RIGHT)
的代码。我稍后会给出更详细的答案。 - Joel Cornett