Tkinter’s Messagebox without the root window

Here is a script that let’s you see the messagebox in pyhton, with tkinter, without having that annoying second window appearing on the screen.

import tkinter as tk
from tkinter import messagebox

root = tk.Tk()
root.overrideredirect(1)
root.withdraw()
messagebox.showinfo("Showinfo", "So many windows!")
root.destroy()

A little function to use messagebox.showinfo more at ease

If we want to use the messagebox without the main window, we can make a function, so that we can use it in many programs without having to rewrite the code and in a more organized way.

import tkinter as tk
from tkinter import messagebox

def info(message, title="ShowInfo"):
    root = tk.Tk()
    root.overrideredirect(1)
    root.withdraw()
    messagebox.showinfo(title, message)
    root.destroy()

info("Messagebox is cool")

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.