Python pyautogui Creating Dialog Boxes














































Python pyautogui Creating Dialog Boxes



Introduction


  • PyAutoGUI is the module of python used to automate and programmatically control the mouse and keyboard.
  • Dialog boxes or message boxes are one of the key features of GUI in python.
  • It prompts the user for taking an action or to give a feedback.
  • There are four message box functions in python. 

alert( ) Function


  • The  alert()  function displays a message box with a text and a single OK button.
  • It has arguments text, title and button.

import pyautogui

pyautogui.alert('This is the message box')

 

                                                       


confirm()Function

 

  • The  confirm()  function displays a message box with OK and Cancel buttons.
  • Customization of number and text of buttons can be done.
  •  It will display OK and Cancel buttons by default.  


import pyautogui

pyautogui.confirm('Please select an option')

 

                                 


 To change the buttons option pass a list of buttons you want-


import pyautogui

pyautogui.confirm('Please select an option',buttons=['M','F'])

 

                      


prompt() Function

 

  • The  prompt()  function displays a message box with text input, OK and Cancel buttons.

 

import pyautogui

pyautogui.prompt('Enter your name')

 

                                  


password() Function

 

  • The  password()  function displays a message box with text input, OK and Cancel buttons.
  • The characters in this are in form of * to show that they are encrypted.


import pyautogui

pyautogui.password('Enter the password')

 

                                  




Comments