私はすべてのtkinter GUI(この場合はtopFrameです)に必要なPanedWindowのフレームを持っています。その下にはたくさんのフレームがあり、ボタンのクリック時にそのフレームを切り替える(画面の上部が固定されているソフトウェアのように、GUIの下部のボタンをクリックするなど)。tkinterのPython 3.5でPanedWindowの上にフレームを表示
私はグリッドレイアウトが必要だと知っています。しかし、それは起こっていないと私はどこでも解決策を取得していない。私はこのトピックでどこでも多くを研究したが、この解決策はどこにもない。ここに私のコードがあります...私は、私がうまく動作していないと感じるコードをコメントに書いています。
#python 3.5
from tkinter import *
#function to raise the frame on button click
def raiseFrame(frame):
frame.tkraise()
m = PanedWindow(height=500, width=1000, orient=VERTICAL)
m.pack(fill=BOTH, expand=1)
#to expand the column and row to fill the extra space
m.grid_columnconfigure(index=0, weight=1) #this code is not working as it should
m.grid_rowconfigure(index=0, weight=1) #this code is not working as it should
#top frame has two buttons which switches the bottom frames
topFrame = Frame(m, bg="blue")
m.add(topFrame)
button1 = Button(topFrame, text="Raise Frame 2", command=lambda: raiseFrame(frame2)) #raises frame 2 on clicking it
button1.pack(side=LEFT)
button2 = Button(topFrame, text="Raise Frame 1", command=lambda: raiseFrame(frame1)) #raises frame 1 on clicking it
button2.pack(side=LEFT)
#bottomframe acts as container for two other frames which i need to switch
bottomframe = Frame(m, bg="orange")
m.add(bottomframe)
frame1 = Frame(bottomframe, bg="yellow")
frame1.grid(row=0, column=0, sticky="news") ## sticky is not working ##
frame2 = Frame(bottomframe, bg="green")
frame2.grid(row=0, column=0, sticky="news") ## sticky is not working ##
label1 = Label(frame1, text="i should change")
label1.pack(padx=10, pady=10)
label2 = Label(frame2, text="i am changed !!")
label2.pack(padx=10, pady=10)
mainloop()
1)私のコードを修正してください。
2)なぜ「topFrame」で私が
topFrame.pack(fill=BOTH, expand=True)
私のコードは、上記の性質を見せているし、それは同じのために行くY. を拡大するだけでなく、Xとの両方を満たしています書かれていなくても、私を説明bottomFrame、それはオレンジ色が通常のフレームで発生しない空間全体を埋めることです。それで、PanedWindowの特別な機能ですか?
私はフレーム1とフレーム2にbottomFrame全体をカバーすることができません。私は多くを研究しましたが、この解決策はどこにもありません。 – Syler
@Syler: 'bottomframe.grid_rowconfigure(0、weight = 1)'と 'bottomframe.grid_columnconfigure(0、weight = 1) 'の2行を追加します。 –
私はあなたのコードを理解し、あなたの助けてくれてありがとう、私はパックとグリッドのジオメトリーをもっと深く理解しています。 – Syler