Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6601831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:48:15+00:00 2026-05-25T18:48:15+00:00

I have built my first few scripts with a nice little GUI on them,

  • 0

I have built my first few scripts with a nice little GUI on them, as the tutorials have shown me, but none of them address what to do for a more complex program.

If you have something with a ‘start menu’, for your opening screen, and upon user selection you move to a different section of the program and redraw the screen appropriately, what is the elegant way of doing this?

Does one just .destroy() the ‘start menu’ frame and then create a new one filled with the widgets for another part? And reverse this process when they press the back button?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:48:15+00:00Added an answer on May 25, 2026 at 6:48 pm

    One way is to stack the frames on top of each other, then you can simply raise one above the other in the stacking order. The one on top will be the one that is visible. This works best if all the frames are the same size, but with a little work you can get it to work with any sized frames.

    Note: for this to work, all of the widgets for a page must have that page (ie: self) or a descendant as a parent (or master, depending on the terminology you prefer).

    Here’s a bit of a contrived example to show you the general concept:

    try:
        import tkinter as tk                # python 3
        from tkinter import font as tkfont  # python 3
    except ImportError:
        import Tkinter as tk     # python 2
        import tkFont as tkfont  # python 2
    
    class SampleApp(tk.Tk):
    
        def __init__(self, *args, **kwargs):
            tk.Tk.__init__(self, *args, **kwargs)
    
            self.title_font = tkfont.Font(family='Helvetica', size=18, weight="bold", slant="italic")
    
            # the container is where we'll stack a bunch of frames
            # on top of each other, then the one we want visible
            # will be raised above the others
            container = tk.Frame(self)
            container.pack(side="top", fill="both", expand=True)
            container.grid_rowconfigure(0, weight=1)
            container.grid_columnconfigure(0, weight=1)
    
            self.frames = {}
            for F in (StartPage, PageOne, PageTwo):
                page_name = F.__name__
                frame = F(parent=container, controller=self)
                self.frames[page_name] = frame
    
                # put all of the pages in the same location;
                # the one on the top of the stacking order
                # will be the one that is visible.
                frame.grid(row=0, column=0, sticky="nsew")
    
            self.show_frame("StartPage")
    
        def show_frame(self, page_name):
            '''Show a frame for the given page name'''
            frame = self.frames[page_name]
            frame.tkraise()
    
    
    class StartPage(tk.Frame):
    
        def __init__(self, parent, controller):
            tk.Frame.__init__(self, parent)
            self.controller = controller
            label = tk.Label(self, text="This is the start page", font=controller.title_font)
            label.pack(side="top", fill="x", pady=10)
    
            button1 = tk.Button(self, text="Go to Page One",
                                command=lambda: controller.show_frame("PageOne"))
            button2 = tk.Button(self, text="Go to Page Two",
                                command=lambda: controller.show_frame("PageTwo"))
            button1.pack()
            button2.pack()
    
    
    class PageOne(tk.Frame):
    
        def __init__(self, parent, controller):
            tk.Frame.__init__(self, parent)
            self.controller = controller
            label = tk.Label(self, text="This is page 1", font=controller.title_font)
            label.pack(side="top", fill="x", pady=10)
            button = tk.Button(self, text="Go to the start page",
                               command=lambda: controller.show_frame("StartPage"))
            button.pack()
    
    
    class PageTwo(tk.Frame):
    
        def __init__(self, parent, controller):
            tk.Frame.__init__(self, parent)
            self.controller = controller
            label = tk.Label(self, text="This is page 2", font=controller.title_font)
            label.pack(side="top", fill="x", pady=10)
            button = tk.Button(self, text="Go to the start page",
                               command=lambda: controller.show_frame("StartPage"))
            button.pack()
    
    
    if __name__ == "__main__":
        app = SampleApp()
        app.mainloop()
    

    start page page 1 page 2

    If you find the concept of creating instance in a class confusing, or if different pages need different arguments during construction, you can explicitly call each class separately. The loop serves mainly to illustrate the point that each class is identical.

    For example, to create the classes individually you can remove the loop (for F in (StartPage, ...) with this:

    self.frames["StartPage"] = StartPage(parent=container, controller=self)
    self.frames["PageOne"] = PageOne(parent=container, controller=self)
    self.frames["PageTwo"] = PageTwo(parent=container, controller=self)
    
    self.frames["StartPage"].grid(row=0, column=0, sticky="nsew")
    self.frames["PageOne"].grid(row=0, column=0, sticky="nsew")
    self.frames["PageTwo"].grid(row=0, column=0, sticky="nsew")
    

    Over time people have asked other questions using this code (or an online tutorial that copied this code) as a starting point. You might want to read the answers to these questions:

    • Understanding parent and controller in Tkinter __init__
    • Tkinter! Understanding how to switch frames
    • How to get variable data from a class
    • Calling functions from a Tkinter Frame to another
    • How to access variables from different classes in tkinter?
    • How would I make a method which is run every time a frame is shown in tkinter
    • Tkinter Frame Resize
    • Tkinter have code for pages in separate files
    • Refresh a tkinter frame on button press
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today I built my first windows service in c#. I have a few problems
I have just built up my first SVN server, along with the mod_dav_svn module
I have two arrays built while parsing a text file. The first contains the
First of all, I know how to build a Java application. But I have
I have built a few custom applications that run on WSS 3 using the
I've seen a few questions like this, but mine is a bit more specific
I'm using a string builder to build some SQL Scripts. I have a few
I have begun to understand a few examples related to currying but I am
I have built my first neural network in python, and i've been playing around
I'm trying to build my first generic list and have run into some problems.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.