wxpython – How can I create a simple message box in Python?

wxpython – How can I create a simple message box in Python?

You could use an import and single line code like this:

import ctypes  # An included library with Python install.   
ctypes.windll.user32.MessageBoxW(0, Your text, Your title, 1)

Or define a function (Mbox) like so:

import ctypes  # An included library with Python install.
def Mbox(title, text, style):
    return ctypes.windll.user32.MessageBoxW(0, text, title, style)
Mbox(Your title, Your text, 1)

Note the styles are as follows:

##  Styles:
##  0 : OK
##  1 : OK | Cancel
##  2 : Abort | Retry | Ignore
##  3 : Yes | No | Cancel
##  4 : Yes | No
##  5 : Retry | Cancel 
##  6 : Cancel | Try Again | Continue

Have fun!

Note: edited to use MessageBoxW instead of MessageBoxA

Have you looked at easygui?

import easygui

easygui.msgbox(This is a message!, title=simple gui)

wxpython – How can I create a simple message box in Python?

The code you presented is fine! You just need to explicitly create the other window in the background and hide it, with this code:

import Tkinter
window = Tkinter.Tk()
window.wm_withdraw()

Right before your messagebox.

Leave a Reply

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