What is winsound.MessageBeep() in Python 3?

Overview

The winsound module in Python 3 provides an interface to interact with the sound playing machinery in Windows. The MessageBeep function plays a built-in Windows sound. The syntax of the MessageBeep function is as follows:

winsound.MessageBeep(type=MB_OK)

Parameters

  • type is a winsoud.MB_ value that specifies which system sound to play. The following table summarizes the sounds available:
winsound Values Corresponding Control Panel Sound
MB_ICONASTERISK Asterisk
MB_ICONEXCLAMATION Exclamation
MB_ICONHAND Critical Stop
MB_ICONQUESTION Question
MB_OK System Default

Note: If -1 is passed, then a default beep is played.

Return value

  • MessageBeep returns None.

Example

The following code provides an example of how to use the MessageBeep function:

import winsound
winsound.MessageBeep(winsound.MB_ICONHAND)

In the example above, the Critical Stop built-in sound is played using the MessageBeep function.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved