Open In App

PyMsgBox module in Python

PyMsgBox is simple, cross-platform, purely implemented in Python for message boxes as JavaScript has. It uses Python’s built-in Tkinter module for its GUI.

Installation

This module does not built-in Python. To install it type the below command in the terminal.



pip install PyMsgBox

There are four functions in PyMsgBox, which follow JavaScript’s message box naming conventions:

alert()

This method shows a message box with text and a single button. It returns the text of the button.



Syntax:

alert(text='', title='', button='OK')




import pymsgbox as a
 
 
b = a.alert("This is alreat", 'Title')
 
# OK whatever you type, it will return OK
print(b)

 

 

Output:

 

confirm()

 

This method displays a message box with OK and Cancel buttons. Number and text of buttons can be customized. Returns the text of the button clicked on.

 

Syntax:

 

confirm(text='', title='', buttons=['OK', 'Cancel'])

 




import pymsgbox as a
 
a.confirm('This is text', 'This is title', ' ')

 

 

Output:

 

prompt()

 

This method displays a message box with text input, and OK & Cancel buttons. Returns the text entered, or None if Cancel was clicked.

 

Syntax:

 

prompt(text='', title='', defaultValue='')

 




import pymsgbox as a
 
 
a.prompt('Text', 'Title', 'Default')

 

 

Output:

 

password()

 

This method will show a masked character in place of every character typed.

 

Syntax:

 

password(text,title,masking-character)

 




import pymsgbox as a
 
a.password("Enter Password", 'This is Title of your application', '', '-')

 

 

Output:

 

 


Article Tags :