How To Use Python EasyGUI Module

EasyGUI is a python module that can implement GUI applications very simple and easily. All the GUI object is created by a python function call, it is not an event-driven framework, you can use it flexibly in your python script. This article will tell you how to use it with some examples.

1. How To Install Python EasyGUI Module.

  1. Open a terminal and run the command pip show easygui to check whether easygui has been installed or not.
    $ pip show easygui 
    WARNING: Package(s) not found: easygui
  2. If it can not find the easygui module, then you can install it with the command pip install easygui in the terminal.
    $ pip install easygui
    Collecting easygui
      Downloading easygui-0.98.2-py2.py3-none-any.whl (92 kB)
         |████████████████████████████████| 92 kB 169 kB/s 
    Installing collected packages: easygui
    Successfully installed easygui-0.98.2
  3. Now you can run the command pip show easygui again to get the python easygui module installation information.
    $ pip show easygui
    Name: easygui
    Version: 0.98.2
    Summary: EasyGUI is a module for very simple, very easy GUI programming in Python.  EasyGUI is different from other GUI generators in that EasyGUI is NOT event-driven.  Instead, all GUI interactions are invoked by simple function calls.
    Home-page: https://github.com/robertlugg/easygui
    Author: easygui developers and Stephen Ferg
    Author-email: [email protected]
    License: BSD
    Location: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
    Requires: 
    Required-by: 
    

2. How To Use Python EasyGUI In Eclipse Pydev.

  1. If you want to use the python easygui module in the eclipse Pydev project, you can follow the below steps.
  2. First, from the command pip show easygui returned data, we can see the easygui module is installed in the directory /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages.
  3. So what you need to do is to add the easygui module installed directory into the eclipse Pydev project PYTHONPATH —> External Libraries.
  4. You can right-click the eclipse Pydev project, then click the Properties menu item in the popup menu list to open the project Properties for dialog window.
  5. Click the PyDev – PYTHONPATH menu item on the left side, then click the External Libraries tab on the dialog right side.
  6. Please make sure the easygui module install directory exists in the External Libraries, if not, click the Add source folder button to add it. You can read the article How To Add Library In Python Eclipse Project to learn more.

3. Run Python EasyGUI Examples.

There list some examples for the easygui functions.

  1. Before you can use easygui function, you must import it into your python script.
    from easygui import *
  2. The function abouteasygui() will display an about dialog that will introduce the easygui module.
    # Import all functions from easygui module.
    from easygui import *
    
    if __name__ == '__main__':
        
        # display the easygui about dialog window.
        abouteasygui()
  3. The function easygui_demo() will display a dialog that contains all the demo of how to use easygui common used functions, but you should import it with the command from easygui.boxes.demo import easygui_demo before using it.
    from easygui.boxes.demo import easygui_demo
    
    if __name__ == '__main__':
    
        # the easygui_demo() function will display all the function's demo.
        easygui_demo()
  4. Easygui function msgbox example.
    from easygui import *
    
    if __name__ == '__main__':
           
        # display a message box.
        title_txt = 'This is title'
        msg_txt = 'This is easygui msgbox message.'
        ret = msgbox(title=title_txt, msg=msg_txt)
        print('msgbox return = ', ret)
    
    ==========================================
    Below is the above code output.
    
    msgbox return = OK
  5. Easygui function ynbox example.
    from easygui import *
    
    if __name__ == '__main__':
        
        # display the ynbox (yes or no box)
        title_txt = 'Demo for ynbox'
        msg_txt = 'Shall I continue?'
        ret = ynbox(title=title_txt, msg=msg_txt, choices = ('Yes', 'No'))
        print('ynbox return = ', ret)
        
    ==========================================
    Output.
    
    ynbox return = False
  6. Easygui function ccbox example.
    from easygui import *
    
    if __name__ == '__main__':
        
        # demo for ccbox (continue or cancel box)
        title_txt = 'Demo for ccbox'
        msg_txt = 'Shall I continue or cancel?'
        ret = ccbox(msg = msg_txt, title = title_txt, choices = ('Continue', 'Cancel'))
        print('ccbox return = ', ret)
    ==========================================
    Output.
    
    ccbox return = True
  7. Easygui function boolbox example.
    from easygui import *
    
    if __name__ == '__main__':
           
        # demo for boolbox
        title_txt = 'Demo for boolbox'
        msg_txt = 'Shall I continue or cancel?'
        ret = boolbox(msg = msg_txt, title = title_txt, choices = ('I like python', 'I do not like python'))
        print('boolbox return = ', ret)
    ===========================================
    Output.
    
    boolbox return = False
  8. Easygui function buttonbox example.
    from easygui import *
    
    if __name__ == '__main__':
            
        # demo for buttonbox
        title_txt = 'Demo for buttonbox'
        msg_txt = 'Shall I continue or cancel?'
        
        btn1 = 'Python'
        btn2 = 'Java'
        btn3 = 'Javascript'
        
        btn_list = []
        btn_list.append(btn1)
        btn_list.append(btn2)
        btn_list.append(btn3)
        ret = buttonbox(msg = msg_txt, title = title_txt, choices = btn_list)
        print('buttonbox return = ', ret)
    ===========================================
    Output.
    
    buttonbox return = Python
  9. Easygui function buttonbox with images example.
    # demo for buttonbox with images.
    title_txt = 'Demo for buttonbox with images'
    msg_txt = 'Which image do you like?'
    
    btn1 = 'Apple'
    btn2 = 'Android'
    
    btn_list = []
    btn_list.append(btn1)
    btn_list.append(btn2)
    
    images_path = ('C:\\Users\\zhaosong\\Pictures\\apple.PNG', 'C:\\Users\\zhaosong\\Pictures\\android.jpg')
    ret = buttonbox(msg = msg_txt, title = title_txt, choices = btn_list, image=images_path)
    print('buttonbox return = ', ret)
    ==============================================
    Output.
    
    buttonbox return = Apple
    
    or
    
    buttonbox return = C:\Users\zhaosong\Pictures\apple.PNG
  10. Easygui function choicebox example.
    from easygui import *
       
    def choicebox_example():
        # demo for ccbox (continue or cancel box)
        title_txt = 'Demo for choicebox'
        msg_txt = 'Select one coding language?'
        ret = choicebox(msg = msg_txt, title = title_txt, choices = ('Python', 'Java', 'Swift'))
        print('choicebox return = ', ret)
                                    
    
    if __name__ == '__main__':
        
        choicebox_example()
    ===============================================
    Output.
    
    
    choicebox return = Python
  11. Easygui function multchoicebox example.
    from easygui import *
    
    def multchoicebox_example():
        # demo for multchoicebox
        title_txt = 'Demo for multchoicebox'
        msg_txt = 'Select multiple coding language?'
        ret = multchoicebox(msg = msg_txt, title = title_txt, choices = ('Python', 'Java', 'Swift'))
        print('multchoicebox return = ', ret)
                                        
    
    if __name__ == '__main__':
        
        multchoicebox_example()
    ================================================
    Output.
    
    multchoicebox return = ['Python', 'Java', 'Swift']
  12. Easygui function textbox example.
    from easygui import *
    
    def textbox_example():
        # demo for multchoicebox
        title_txt = 'Demo for textbox'
        msg_txt = 'Input text in the below text area.'
        ret = textbox(msg = msg_txt, title = title_txt)
        print('textbox return = ', ret)
                                            
    
    if __name__ == '__main__':
        
        textbox_example()
    
    ======================================================
    Output.
    
    textbox return =  I love python.
  13. Easygui function codebox example.
    from easygui import *
    import os
    
    def codebox_example():
        # demo for multchoicebox
        title_txt = 'Demo for codebox'
        msg_txt = 'Below python source code are loaded from a python file.'
        
        file_path = 'C:\WorkSpace\Work\dev2qa.com-example-code\PythonExampleProject\com\dev2qa\example\gui\EasyguiExample.py'
        
        file = open(file_path)
        
        file_content = file.readlines();
        
        file.close()
        
        ret = codebox(msg = msg_txt, title = title_txt, text= file_content)
        print('codebox return = ', ret)                                         
                                            
    
    if __name__ == '__main__':
           
        codebox_example()
    =========================================================
    Output.
    
    codebox return = 
    from easygui import *
    import os
    
    def codebox_example():
        # demo for codebox
        title_txt = 'Demo for codebox'
        msg_txt = 'Below python source code are loaded from a python file.'
        
        # read a python source file content.
        file_path = 'C:\WorkSpace\Work\dev2qa.com-example-code\PythonExampleProject\com\dev2qa\example\gui\EasyguiExample.py'
        
        file = open(file_path)
        
        file_content = file.readlines();
        
        file.close()
        
        # show python source code in the codebox.
        ret = codebox(msg = msg_txt, title = title_txt, text= file_content)
        print('textbox return = ', ret)                                            
                                            
    if __name__ == '__main__':
            
        codebox_example()
  14. Easygui function enterbox example.
    from easygui import *
    
    def enterbox_example():
        # demo for enterbox
        title_txt = 'Demo for enterbox'
        msg_txt = 'Enter the coding language that you prefer.'
        ret = enterbox(msg = msg_txt, title = title_txt)
        print('enterbox return = ', ret)   
                                            
    
    if __name__ == '__main__':
    
        enterbox_example()
    ======================================
    Output.
    
    enterbox return =  python
  15. Easygui function integerbox example.
    from easygui import *
    
    def integerbox_example():
        # demo for enterbox
        title_txt = 'Demo for integerbox'
        msg_txt = 'Enter an integer between 90 - 100.'
        ret = integerbox(msg = msg_txt, title = title_txt)
        print('integerbox return = ', ret)                                          
    
    if __name__ == '__main__':
            
        integerbox_example()
    ================================================================
    Output.
    
    If you enter an integer value smaller than or bigger than the integer range, it will prompt an alert dialog. otherwise, it will return the user entered integer value.
    
  16. Easygui function passwordbox example.
  17. Easygui function multenterbox example.
  18. Easygui function multpasswordbox example.
  19. Easygui function enterbox with an image example.
  20. Easygui function filesavebox example.
  21. Easygui function fileopenbox example.
  22. Easygui function diropenbox example.
  23. Easygui function exceptionbox example.
0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x