How to create a new window with Tkinter in Python

  1. Import Tkinter

To start we need to import tkinter the start lets us import everything from the packet.

from tkinter import *
  1. Create a main window.

To create a new window we first need to create our main window.

  1. Create a window
window = Tk()
  1. To start the event loop we need to type mainloop( )
window.mainloop()
  1. Create the new window

Now we create every that we need for the window,
at the end it shoud look like this.

import tkinter as tk

def create_new_window():
    # Create a new window
    new_window = tk.Tk()
    new_window.title("Persistent Window")
    new_window.geometry("300x200")

    # Add a label to the window
    label = tk.Label(new_window, text="Close me, and I'll come back!")
    label.pack(pady=20)

    # Bind the close event to recreate the window
    new_window.protocol("WM_DELETE_WINDOW", lambda: on_close(new_window))

    new_window.mainloop()

def on_close(window):
    # Destroy the current window and create a new one
    window.destroy()
    create_new_window()

PS. Hatte kein Bog den rest jetzt noch in einzelnen schriten aufzuzählen.