フレームをキャンバスに埋め込み、スクロールバーを次のように追加して、スクロール可能なフレームを作成する方法を学びました。
def __add_widget_features(self, feat_tab):
table_frame = ttk.Frame(feat_tab)
table_frame.pack(fill=BOTH, expand=True)
self.__make_grid(table_frame)
####subframe####
self.canvas = Canvas(table_frame, borderwidth=0, background="#ffffff")
self.frame = LabelFrame(self.canvas, background="#ffffff", text="Timetable")
self.vsb = ttk.Scrollbar(table_frame, orient="vertical", command=self.canvas.yview)
self.canvas.configure(yscrollcommand=self.vsb.set)
self.vsb.pack(side="right", fill="y")
self.canvas.pack(side="right", fill="both", expand=True)
self.canvas.create_window((4,4), window=self.frame, anchor="nw",
tags="self.frame")
self.frame.bind("<Configure>", self.OnFrameConfigure)
私のプログラムには、複数のタブを作成する GUI があります。スクロール可能なキャンバスは 1 つのタブでうまく機能しますが、同じコードを別のタブに追加しようとすると、そのタブでスクロールバーが機能しません。最初のタブのコード ブロックをコメント アウトすると、他のタブでも問題なく動作します。2 番目のタブのすべての要素に別の名前を付けようとしましたが (それが問題だった場合に備えて)、「自己」を削除しようとしました。名前の一部ですが、どれも役に立ちませんでした。私はPythonを初めて使用するので、単純なものが欠けていると確信しています。問題の写真を投稿しようとしましたが、私の担当者はまだ十分に高くありません. どんな助けでも素晴らしいでしょう。
更新: Brionius の提案によると、ノートブックを作成する関数は次のとおりです。
def __add_widget_datawindow(self):
'''(FordTIPGui) -> NoneType
Populate the data_window with widgets.
'''
# add data_window frame
data_frame = ttk.Frame(self.data_window)
data_frame.pack(fill=BOTH, expand=True)
self.__make_grid(data_frame)
self.add_menubar(self.data_window, "other") # add menubar
# add subframes and make them into a grid
button_frame = ttk.Frame(data_frame)
button_frame.grid(row=9, column=0, rowspan=1, columnspan=10,sticky=W+E+N+S)
self.__make_grid(button_frame)
nb_frame = ttk.Frame(data_frame)
nb_frame.grid(row=0, column=0, rowspan=9, columnspan=10, sticky=W+E+N+S)
## add widgets to subframes ##
# button_frame
disc_button = ttk.Button(button_frame, text="Disconnect", command=lambda:self.disconnect())
disc_button.grid(row=10, column=0, columnspan=1, sticky=W+E+N+S)
# nb_frame
nb = ttk.Notebook(nb_frame) # create notebook
nb.pack(fill=BOTH, expand=True)
# create frames for tabs
tab_frame1 = ttk.Frame(nb)
tab_frame2 = ttk.Frame(nb)
tab_frame3 = ttk.Frame(nb)
tab_frame4 = ttk.Frame(nb)
tab_frame5 = ttk.Frame(nb)
self.__make_grid(tab_frame1)
self.__make_grid(tab_frame2)
self.__make_grid(tab_frame3)
self.__make_grid(tab_frame4)
self.__make_grid(tab_frame5)
# add tabs
nb.add(tab_frame1, text='Confidential1 View')
nb.add(tab_frame2, text='Confidential2 View')
nb.add(tab_frame3, text='Confidential3 View')
nb.add(tab_frame4, text='Confidential4 View')
nb.add(tab_frame5, text='Confidential5 View')
# add widgets
self.__add_widget_group(tab_frame1)
self.__add_widget_feature(tab_frame2)
self.__add_widget_signal(tab_frame3)
self.__add_widget_features(tab_frame4)
self.__add_widget_timetable(tab_frame5)
問題の写真: http://www.use.com/supersize.pl?set=3059c6e412c1416578a7