Tkinter: Many windows with tkinter when you start a script

Let’s see how to create many windows with tkinter, the built in module in Python.

If you are new to the free programming language Python, go to https:\\python.org and you will se something like this

Click on that link and choose the version of python for your pc.

After you made that, you are ready to start learning how to make a GUI with Python and start 3 windows at start with the main window, adding also a label to each one with a different text on each one. Enjoy.

One window

The code to make many windows at start with tkinter and python

Here is the code

# I was asked to make 3 pop up window at start, so I made this script
# you can find the video tutorial here:
# the repository is here: https://github.com/formazione/tkinter_tutorial.git
# GiovanniPython on YT
# @pythonprogrammi on X


import tkinter as tk


def new_win(name,
		labeltext="",
		font="Arial 20"):
	x = tk.Toplevel(root)
	x.title(name)
	x.label = tk.Label(x,
		font=font,
		text=labeltext)
	x.label.pack()
	return x


root = tk.Tk()
root.title("MAIN WINDOW")
x = new_win("POP 1",
	"If you have questions or something to ask, write it in the comments")
print(x)
y = new_win("POP 2",
	"That's all")
print(y)
z = new_win("POP 3",
	"Bye remember to subscribe, so you do not lose anything")
print(z)

root.mainloop()

If you want to see the code in the repository with other examples of tkinter:

The new_window.py repository

https://github.com/formazione/tkinter_tutorial.git

The video tutorial on my Youtube channel @GiovanniPython


Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.