Create more windows with tkinter

Spread the love

One thing that I think could be useful is to create more windows using tkinter for a program to make it easy to manage different things to do, without having to put too many stuffs in the same window. So here is the final code, after the image of the windows generated in the example:

First you create the main window

There is a way to open different windows through buttons writing less code:

  • butnew to create a button that opens a new window calling new_window function
  • new_window is called clicking the button

For every new window you need to create a new class (passed as argument in butnew function) like this:

Why not to create another window, being so easy?

And you can go on this way further writing all the windows you need.

at the end you create an istance of the first window in this loop:

You will find the code below, after this image, and the video with the live coding too.

Video: making multiple windows with Python and tkinter

P.S.: in the video there is a little mistake; the label in the third window must be attached to self.frame and not to master. So I changed in the code above:

self.label = tk.Label(master, text=”THIS IS ONLY IN THE THIRD WINDOW”)


self.label = tk.Label(self.frame, text=”THIS IS ONLY IN THE THIRD WINDOW”)

Some restyling of the code

Now you can open the windows only once (specific) at the time

This is it

More windows with tkinter (new version)

Subscribe to my youtube channel

Tkinter test for students

Tkinter articles

Pygame's Platform Game

Other Pygame's posts


Python and Powerpoint

Pdf made with Python