[英]Positioning Canvas in window - Tkinter/python
有沒有辦法在窗口中放置畫布並在它周圍放置一個框架?我只找到了如何在畫布內定位對象。
您可以創建一個框架,然后將您的小部件放入其中:
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)
以上將在單個框架內為您提供兩個並排的畫布。 當您調整包含窗口的大小時,它們會增大和縮小。
您可以使用 place() 函數代替 pack() 並執行以下操作:
canvas.place(relx=0.5, rely=0.5, anchor=CENTER)
這將把它放在中心。
就像前面提到的 fortyTwo102 一樣, 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)
來源(和更多有用的信息): https : //www.tutorialspoint.com/python/tk_place.htm
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.