tkinter showerror creating blank tk window

Ecko picture Ecko · Jun 16, 2015 · Viewed 7k times · Source

I have a program that needs to display graphical error messages to users. It is a tkinter GUI, so I am using tkinter.messagebox.showerror

When I call showerror, it shows the error, but also creates a blank "tk" window, the kind created when an instance of the Tk class is called, like root = Tk().

from tkinter.messagebox import showerror
showerror(title = "Error", message = "Something bad happened")

Produces

Results Of Above Code

How can I make this blank window not appear?

Answer

maccartm picture maccartm · Jun 16, 2015
from Tkinter import *
from tkMessageBox import showerror
Tk().withdraw()
showerror(title = "Error", message = "Something bad happened")

Calling Tk().withdraw() before showing the error message will hide the root window.

Note: from tkinter import * for Python 3.x