Mar-30-2019, 07:13 PM
Okay new question, still related to classes and tkinter though:
How do I display the contents of a frame from object A, in another frame from object B?
Example...
How do I display the contents of a frame from object A, in another frame from object B?
Example...
import tkinter as tk import tkinter.ttk as ttk class MainFrame(tk.Tk): ''' _Target_ for insertion of widgets to display from another frame constructed from another class. ''' def __init__(self, parent=None): super().__init__(parent) self.build_mb() self.build_nb() def build_mb(self): menu_bar = tk.Menu(self) self.config(menu=menu_bar) options_menu = tk.Menu(menu_bar, tearoff=0) menu_bar.add_cascade(label="Options", menu=options_menu) options_menu.add_command(label="Quit", command=self.destroy) def build_nb(self): nb = ttk.Notebook(self) nb.grid() tab_one = tk.Frame(nb) # <-- target actual # # nb.add(tab_one, text='Entries') tab_two = tk.Frame(nb) nb.add(tab_two, text='Unused') class TabOne(tk.Frame): ''' _This_ is the frame to display in "tab_one" of the MainFrame object. ''' def __init__(self, parent=None): super().__init__(parent) self.build_tab() def build_tab(self): entry = ttk.Entry() entry.grid(column=0, row=0) submit = ttk.Button(text='Submit') submit.grid(column=1, row=0) def run_main(): main_nb = MainFrame() tab1 = TabOne(main_nb) #This doesn't work; "main_nb.tab_one" (or whatever) throws error. main_nb.mainloop() if __name__ == '__main__': run_main()Is it possible to get the widgets in the frame named tab1 to display in the notebook this way, or must it all be constructed together?