你好,我想我有一个python tkinter设计问题 . 我查看this以更好地构建我的代码 . 我不想单独更改所有小部件的配置,并且想要使用我在this问题中找到的 parent_widget.winfo_children() 命令 .

我想知道有没有更好的方法来不单独配置小部件,但更新其字体和样式 .

这是我的代码和当前行为:

class TabOne(Frame):

    def __init__(self, parent):
        Frame.__init__(self, parent)
        self.tab1_note = ttk.Notebook(self,width=parent.winfo_screenwidth(), height=parent.winfo_screenheight())

        tab1_open_observations = ttk.Frame(self.tab1_note)
        tab1_closed_observations = ttk.Frame(self.tab1_note)

        self.tab1_note.add(tab1_open_observations, text= "Open Projects")
        self.tab1_note.add(tab1_closed_observations, text= "Closed/Deferred Projects")
        self.tab1_note.pack()

        self.tab_two_load(tab1_open_observations)
        self.tab_three_load(tab1_closed_observations)
        widget_list = []
        widget_list.extend(tab1_open_observations.winfo_children())
        widget_list.extend(tab1_closed_observations.winfo_children())

        for wid in widget_list:
            try:
                wid.configure(font = 'helvetica 12')
            except:
                pass

     def tab_one_load(self,tab1_refresh_db):
     def tab_two_load(self,tab1_open_observations)

class TabTwo(Frame):
class TabThree(Frame):

class MainWindow(Frame):
    def __init__(self, window, **kwargs):
        Frame.__init__(self, window, **kwargs)
        self.load_ui()

    def load_ui(self):
        self.note = ttk.Notebook(self,width=self.window.winfo_screenwidth()-(2*self.pad), height=self.window.winfo_screenheight()-(2*self.pad))

        self.tab1 = TabOne(self.note)
        self.tab2 = TabTwo(self.note)
        self.tab3 = TabThree(self.note)

        self.note.pack()

def main():
    window = Tk()
    window.title('Productivity Tool')
    app = MainWindow(window)
    app.pack(side="top", fill="both", expand=True)
    window.mainloop()

if __name__ == '__main__':
    main()

依赖下拉列表的当前行为(下面的代码):

enter image description here

如果我在每个依赖的OptionsMenu下面添加 project_module_dropdown.configure(font='helvetica 12') ,则第二个列表不会重叠 . 这是函数的更多代码 tab_two_load()

def tab_two_load(self,tab1_open_observations):

    def update_modules(a,b,c):

        proj_mo_names = [module[0] for module in project_modules]
        proj_mod_select.set(proj_mo_names[0])
        project_module_dropdown = OptionMenu(tab1_open_observations,proj_mod_select,*proj_mo_names)
        project_module_dropdown.configure(font='helvetica 12')
        project_module_dropdown.grid(row=2, column=1,padx=10, pady=10)

    proj_select = StringVar(tab1_open_observations,value='Default Text')
    proj_select.trace('w',update_modules)

    proj_mod_select = StringVar(tab1_open_observations,value='Default Text')
    proj_mod_select.trace('w',update_teams)
    proj_mod_select.trace('w',update_artifacts)

    proj_names = [project[1] for project in projects]
    proj_select.set(proj_names[0])
    project_dropdown = OptionMenu(tab1_open_observations,proj_select,*proj_names)
    project_dropdown.grid(row=1,column=1,padx=10,pady=10)

我认为问题在于我如何构建我的代码,但我相信我已经很好地划分了代码,但我愿意接受建议 . 这不是一个代码审查问题 . 我的问题是重叠drowdowns,但我觉得我的代码中有一些我想避免的重复 . 任何帮助都很棒 . 谢谢 .

我希望这是我想要的行为而不添加 project_module_dropdown.configure(font='helvetica 12')

enter image description here