'How To Put Widgets In A New Tkinter Window?

I wanted to add widgets to a new tkinter window, so I tried this:

old_window = Tk()
new_window = Tk()
    old_window.destroy()
    new_window.geometry("750x550")
    image = Label(new_window, image = dernier).pack
    button1 = Button(new_window, text = "Oui", font= ("", 25), command = button1_press).place(x=250, y=475)
    button2 = Button(new_window, text = "Non", font= ("", 25), command = button2_press).place(x=425, y=475)

But, just a basic window pops out, with nothing inside.

Python version: 3.9.7

Integrated Development Environnement (Also known as IDE): Visual Studio Code.



Solution 1:[1]

The tk.Tk() class isn't just a window, it's also what controls the entire application and has an associated Tcl interpreter. Creating multiple of these, and destroying them part way through an application, can cause many problems. Instead, for creating a new window, use the tk.Toplevel() class.

For example:

import tkinter as tk

root = tk.Tk()
a = tk.Toplevel()
b1 = tk.Button(a, text="new toplevel", command=lambda: tk.Toplevel())

root.mainloop()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lecdi