Bottom Page

Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How to create mutiple tabs in tkinter using oops
i am working on something and i know how to use notebook widget in tkinter and pack different stuff in each of the tabs in notebook but i want to know how i can do that it in object oriented approach.
from Tkinter import *
from ttk import *

class NotebookDemo(Frame):

    def __init__(self, isapp=True, name='notebookdemo'):
        Frame.__init__(self, name=name)
        self.pack(expand=Y, fill=BOTH)
        self.master.title('Notebook Demo')
        self.isapp = isapp

    def _create_widgets(self):

    def _create_demo_panel(self):
        demoPanel = Frame(self, name='demo')
        demoPanel.pack(side=TOP, fill=BOTH, expand=Y)

        # create the notebook
        nb = Notebook(demoPanel, name='notebook')
        # extend bindings to top level window allowing
        #   CTRL+TAB - cycles thru tabs
        #   SHIFT+CTRL+TAB - previous tab
        #   ALT+K - select tab using mnemonic (K = underlined letter)

        nb.pack(fill=BOTH, expand=Y, padx=2, pady=3)

    def _create_descrip_tab(self, nb):
        # frame to hold contentx
        frame = Frame(nb, name='descrip')

        # widgets to be displayed on 'Description' tab
        msg = [
            "Ttk is the new Tk themed widget set. One of the widgets ",
            "it includes is the notebook widget, which provides a set ",
            "of tabs that allow the selection of a group of panels, ",
            "each with distinct content. They are a feature of many ",
            "modern user interfaces. Not only can the tabs be selected ",
            "with the mouse, but they can also be switched between ",
            "using Ctrl+Tab when the notebook page heading itself is ",
            "selected. Note that the second tab is disabled, and cannot "
            "be selected."]

        lbl = Label(frame, wraplength='4i', justify=LEFT, anchor=N,
        neatVar = StringVar()
        btn = Button(frame, text='Neat!', underline=0,
                         command=lambda v=neatVar: self._say_neat(v))
        neat = Label(frame, textvariable=neatVar, name='neat')

        # position and set resize behaviour
        lbl.grid(row=0, column=0, columnspan=2, sticky='new', pady=5)
        btn.grid(row=1, column=0, pady=(2,4))
        neat.grid(row=1, column=1,  pady=(2,4))
        frame.rowconfigure(1, weight=1)
        frame.columnconfigure((0,1), weight=1, uniform=1)

        # bind for button short-cut key
        # (must be bound to toplevel window)
        self.winfo_toplevel().bind('<Alt-n>', lambda e, v=neatVar: self._say_neat(v))

        # add to notebook (underline = index for short-cut character)
        nb.add(frame, text='Description', underline=0, padding=2)

    def _say_neat(self, v):
        v.set('Yeah, I know...')
        self.after(500, v.set(''))

    # =============================================================================
    def _create_disabled_tab(self, nb):
        # Populate the second pane. Note that the content doesn't really matter
        frame = Frame(nb)
        nb.add(frame, text='Disabled', state='disabled')

    # =============================================================================
    def _create_text_tab(self, nb):
        # populate the third frame with a text widget
        frame = Frame(nb)

        txt = Text(frame, wrap=WORD, width=40, height=10)
        vscroll = Scrollbar(frame, orient=VERTICAL, command=txt.yview)
        txt['yscroll'] = vscroll.set
        vscroll.pack(side=RIGHT, fill=Y)
        txt.pack(fill=BOTH, expand=Y)

        # add to notebook (underline = index for short-cut character)
        nb.add(frame, text='Text Editor', underline=0)

if __name__ == '__main__':
taken from this gist
yeah if those those tabs are implemented in different classes then??

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Tkinter: Create an homepage look like PeroPuri 8 415 Jun-26-2020, 12:57 AM
Last Post: menator01
  Create image on a Toplevel using tkinter ViktorWong 3 925 Jun-13-2020, 03:21 PM
Last Post: deanhystad
  [Tkinter] Need help please properly putting tabs within a PanedWindow JackMack118 2 423 Dec-08-2019, 03:02 PM
Last Post: balenaucigasa
  [PyQt] Drag items across tabs Alfalfa 5 740 Sep-01-2019, 11:58 PM
Last Post: Alfalfa
  [Tkinter] Adding space between Notebook tabs Columbo 4 999 Jul-10-2019, 10:46 PM
Last Post: Columbo
  [Tkinter] How to get a tabs works exactly same as google chrome sarthak260 0 892 Mar-07-2019, 10:45 AM
Last Post: sarthak260
  [Tkinter] How to create multilple tabs in tkinter from different classes Rishav 5 11,321 Jul-11-2018, 11:59 AM
Last Post: CCChris91
  Using a class to create instances of Tkinter Toplevel() windows nortski 2 4,866 Mar-27-2018, 11:44 AM
Last Post: nortski

Forum Jump:

Users browsing this thread: 1 Guest(s)