我試圖讓畫布位于可用空間的中心,但它一直粘在螢屏的北部......這是一張圖片
這是代碼
def newsetup(filelocation):
global width, height
global stage, img_id, imgtk
for widgets in root.winfo_children():
widgets.destroy()
root.config(bg = '#454545')
iconsframewidth = int(screen_width / 20)
iconsframe = Frame(root, width = iconsframewidth, bg = '#2a2a2a')
iconsframe.pack(side = 'left', expand = False, fill = 'y')
iconsframe.pack_propagate(0)
sep1frame = Frame(root, bg = '#1a1a1a', width = 10, relief = 'sunken')
sep1frame.pack(side = 'left', expand = False, fill = 'y')
optionsframe = Frame(root, bg = '#2a2a2a', height = 100)
optionsframe.pack(side = 'top', expand = False, fill = 'x')
optionsframe.pack_propagate(0)
sep2frame = Frame(root, bg = '#1a1a1a', height = 10, relief = 'sunken')
sep2frame.pack(side = 'top', expand = False, fill = 'x')
propertyframe = Frame(root, bg = '#2a2a2a', width = 150)
propertyframe.pack(side = 'right', expand = False, fill = 'y')
propertyframe.pack_propagate(0)
sep3frame = Frame(root, bg = '#1a1a1a', width = 10, relief = 'sunken')
sep3frame.pack(side = 'right', expand = False, fill = 'y')
stageframe = Frame(root, bg = '#454545')
stageframe.pack(side = 'top', expand = True, fill = 'both')
stageframe.pack_propagate(0)
stage = Canvas(stageframe, width = width, height = height)
stage.pack(anchor = CENTER)
root.update()
pencilbutton = Button(iconsframe, image = pencilimg, borderwidth = 0, bg = '#2a2a2a', fg = '#2a2a2a', relief = 'flat')
pencilbutton.pack(anchor = W)
imgtk = ImageTk.PhotoImage(Image.open(filelocation))
img_id = stage.create_image(stage.winfo_width() / 2, stage.winfo_height() / 2, image = imgtk)
stage.image = imgtk
stage.bind('<Configure>', PhotoEditing.stageresize)
我試過使用錨它沒有用......我有一個想法把畫布放在框架中,但框架沒有填滿整個空白區域
uj5u.com熱心網友回復:
TL;DRexpand=True打包畫布時添加。
打包器通過將小部件放置在可用空白空間的一側來作業,并將其置于分配的空間中。默認情況下,分配的空間將盡可能小以適合小部件。
沿頂部或底部包裝某物時,如果您希望它垂直居中,則需要告訴包裝器將分配的空間擴展為所有剩余空間。然后,小部件將在剩余空間中水平和垂直居中。
我還建議始終明確設定邊,以便更清楚您的意圖是什么。
stage.pack(side="top", anchor = CENTER, expand=True)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/474310.html
