Alert boxes in Python?

Alert boxes in Python?

what about this:

import win32api

win32api.MessageBox(0, hello, title)


win32api.MessageBox(0, hello, title, 0x00001000) 

will make the box appear on top of other windows, for urgent messages. See MessageBox function for other options.

For those of us looking for a purely Python option that doesnt interface with Windows and is platform independent, I went for the option listed on the following website: (archived link:

# Python 3.x code
# Imports
import tkinter
from tkinter import messagebox

# This code is to hide the main tkinter window
root = tkinter.Tk()

# Message Box
messagebox.showinfo(Title, Message)

You can choose to show various types of messagebox options for different scenarios:

  • showinfo()
  • showwarning()
  • showerror ()
  • askquestion()
  • askokcancel()
  • askyesno ()
  • askretrycancel ()

edited code per my comment below

Alert boxes in Python?

GTK may be a better option, as it is cross-platform. Itll work great on Ubuntu, and should work just fine on Windows when GTK and Python bindings are installed.

from gi.repository import Gtk

dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.INFO,
            Gtk.ButtonsType.OK, This is an INFO MessageDialog)
    And this is the secondary text that explains things.)
print INFO dialog closed

You can see other examples here. (pdf)

The arguments passed should be the gtk.window parent (or None), DestroyWithParent, Message type, Message-buttons, title.

Leave a Reply

Your email address will not be published. Required fields are marked *