1

以下は、ウィンドウのサイズが変更されたときにウィジェットを画面の中央にとどめようとする試みです。sticky='ew'つまり、フレームがパックされて展開されたグリッドの通常の動作を意味しfill='x'ます。私が何を意味するかを示すデモコードを次に示します。

from Tkinter import Frame,Button,Label
from ttk import Notebook

root = Frame()
root.pack(expand=True,fill='both')
nb = Notebook(root)

btn_f = Frame(nb)
Button(btn_f, text="Button Packed").pack(pady=100,padx=100)
# btn_f.pack(expand=True,fill='both') #makes no difference if this is removed

lbl_f = Frame(nb)
Label(lbl_f, text="This label is in a grid").grid(pady=100,sticky='ew')
# lbl_f.grid() #makes no difference if this is removed

nb.add(btn_f, text="Button")
nb.add(lbl_f, text="Label")

nb.pack(expand=True,fill='x')

root.mainloop()

私の疑いは、パックと展開をコメントアウトすることについて私が発見したことと関係があります. Notebook の add メソッドは、フレームの配置方法を処理する独自のレイアウト マネージャーを実行しますか? 私が求めているのは、パックを使用して最初のタブで示したように、グリッドを中央に配置する効果をどのように達成するかということです。

4

1 に答える 1