Current post is on how to show message box in Python 3.2 running on Microsoft Windows OS.
import ctypes
Next we need is the messagebox function pointer
messageBox = ctypes.windll.user32.MessageBoxW *
After having the function pointer, we just need to call the function with required arguments.
returnValue = messageBox(ParentHandle,Error Text,Title Text,ButtonEnumValue)
where,
ParentHandle = Handle to parent window
Error Text = Text one wants to show to end user
Title Text = Text that will appear on Title bar of message box
ButtonEnumValue = Which button one needs to show
Detailed information can be found on Microsoft MessageBox Documentation
Based on return value, one can take the required action.
Example 1: Message Box with OK button.
import ctypes
messageBox = ctypes.windll.user32.MessageBoxW
returnValue = messageBox(None,"Message Box!!!","Hello",0x40 | 0x0)
Example 2: Message Box with OK-Cancel button & ReturnValue Check
import ctypes
messageBox = ctypes.windll.user32.MessageBoxW
returnValue = messageBox(None,"Message Box!!!","Hello",0x40 | 0x1)
if returnValue = = 1:
print("Pressed OK")
elif returnValue = = 2:
print("Pressed Cancel")
* Python 3.x takes unicode only.
No comments:
Post a Comment