I want to add widgets to a new 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, no widgets, nothing.
Python version: 3.9.7
Integrated Development Environnement (Also known as IDE): Visual Studio Code.
CodePudding user response:
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()