It looks like if you type:
from tkinter import *
messagebox.showinfo("App", "test")
There will be 2 windows open instead of one. Why? And How can I fix it?
It looks like if you type:
from tkinter import *
messagebox.showinfo("App", "test")
There will be 2 windows open instead of one. Why? And How can I fix it?
There is no way to destroy it knowing only the title, though I suppose you could iterate over all known widgets looking for one with a given title.
What you want to do instead is save a reference to the window, and then call destroy()
on the reference. In the following example, root
is a reference to the window created by Tk()
.
import tkinter as tk
root = tk.Tk()
Later, you can destroy that window with the following:
root.destroy()
The behavior you said is normal based on your updated code. If you don't want the root window being shown, create it manually and hide it before calling messagebox.showinfo()
, then destroy the root window after the showinfo()
is closed:
from tkinter import *
from tkinter import messagebox
root = Tk()
root.withdraw()
messagebox.showinfo("App", "test")
root.destroy()