有人可以幫我解決我在Tkinter中遇到的問題嗎?Tkinter - 無法將按鈕放在中間帆布/框架
我想創建三個幀/畫布在彼此之下。一旦我在中間畫布上放置了任何小部件(按鈕/標籤),畫布的位置就會向下移動。
這裏是我的代碼:
import tkinter as tk
class GameMain:
def __init__(self):
root = tk.Tk()
top_bg = tk.PhotoImage(file="TopFrame.png")
root.geometry("1280x900+3+3")
cv=tk.Canvas(root,width=1280,height=100)
cv.pack(side="top",fill="both",expand="yes")
cv.create_image(0,0,image=top_bg,anchor='nw')
Btn1 = tk.Button(cv,text="button1")
Btn1.grid(row=0,column=0,padx=5,pady=5)
Btn2 = tk.Button(cv,text="Button2")
Btn2.grid(row=1,column=0,padx=5,pady=5)
mcv=tk.Canvas(root,width=1280,height=700,bg="red",border=1)
mcv.pack(side="top",fill="both",expand="yes")
#Once I placed the following button, middle canvas moved down and shows empty spaces lot
Btn3 = tk.Button(mcv,text="button1")
Btn3.pack(padx=5,pady=5)
Btn4 = tk.Button(mcv,text="Button2")
Btn4.pack(padx=5,pady=5)
bcv=tk.Canvas(root,width=1280,height=100,bg="yellow")
bcv.pack(side="top",fill="both",expand="yes")
root.mainloop()
GameMain()
你想讓這三幅畫布保持完全的高度嗎? –