SoFunction
Updated on 2024-11-10

Python-based EasyGUI Learning Practice

01_msgbox

# Use the easygui function to directly import easygui modules
import easygui

# Use easygui when you need a popup box.
# msgbox(m) method, outputs a message box with the contents of m.
# msg = message 。
('Hello, this is easygui module.')
('It's a hopeful day, too!')
# (m,t,b) has three parameters.
# m is the message message displayed, t is the title tittle of the message box, and b is the button button of the message box.
('May I ask if you're ready?','Problem','Punch and Judy')

Run results:

在这里插入图片描述

02_ccbox

# Use the easygui function, or import the entire easygui package directly
from easygui import *

msgbox('Hello, this is easygui pack.')
# ccbox(m,t) method, you can set two buttons in the selection box
# The default buttons for the selection box are continue and cancel
# ccbox(m,t,c) method, you can modify the button information of the select box continue and cancel
ccbox('May I ask if you're ready?','Problem')
ccbox('Are you ready, please???','Ask again!',['yes','no'])

Run results:

在这里插入图片描述

04_choicebox

import easygui as g
('Hello!')

# (m,t,b) method, which allows you to set multiple options
reply =('Today is also a day full of hope. \n\nPlease are you ready for it?','Problem',['yes','no','emm'])

if reply=='yes':
    ('Your answer is:'+reply+'\n\n Awesome!')
elif reply=='no':
    ('Your answer is:',+reply+''\n\n Grab a hold of yourself and pull yourself together!'')
else:
    (''Make a decision now don't dawdle!'')

Run results:

在这里插入图片描述

05_image

import easygui as g

# () method, you can set the button variables and you can insert images.
(''Do you see Hu Wei growing handsome?'','Soul Questioning',['Cool!','Not handsome!','emm'],image='')

Run results:

在这里插入图片描述

06_multchoicebox

import easygui as g

# () method, which defines the multi-selector box
c = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Zhou Tian']

reply = ('What days of the week do you have classes?','Problem',c)
prompt = 'Mid-week'+str(reply)+'Have a lesson'
(prompt)

Run results:

在这里插入图片描述

07_enterbox

import  easygui as g

# () method, text input box.
reply = ('Do you love me?','Soul Questioning')
prompt = 'Your answer is:'+reply+'\n\nThank you!'
(prompt)

Run results:

在这里插入图片描述

08_multenterbox

import easygui as g
m = 'Enter account registration information:\n\n\n'
t = 'Registration system'
f = ['Username','Password','Telephone']
# method, you can define a multi-input box
# fields options, which are topics that correspond to each line of input
# When it comes to complex easygui, it's simpler to define 'variable name = variable property value'.
(msg=m,title=t,fields=f)

Run results:

在这里插入图片描述

09_passwordbox

import easygui as g

# method, you can define the password input box
# For password input characters, will be masked by *** conformity
('Please enter the password:','Login system')

Run results:

在这里插入图片描述

10_multpasswordbox

import easygui as g
# method, you can define a multi-line password input box.
# Only if the password is entered on the last line is it masked by the *** conforming
m = 'Please enter your account registration information:'
t = 'Account Registration System'
f = ['Username','Telephone','Mailbox','Password']
(msg=m,title=t,fields=f)

Run results:

在这里插入图片描述

11_textbox

import easygui as g
# method, you can define a text output box
# where the text variable can be defined as the text to be outputted
file_name = ('Please enter a filename:')
m = 'Documentation'+file_name+' reads as follows: '
t = 'textbox'
file = open(file_name,encoding='utf-8')
(msg=m,title=t,text=())
()

Run results:

在这里插入图片描述

在这里插入图片描述

12_diropenbox

import easygui as g
# method, which defines a file selection box
# The returned data is the selected file name and path
# diropenbox method to select folders
direction = ()
(direction)

13_fileopenbox

import easygui as g
# method, similar to the diropenbox method.
# fileopenbox method, can only select files, not folders
direction = ()
(direction)

14_filesavebox

import easygui as g
import os
# Set default in fileopen method to filter file types, e.g. '*.txt'
direction = (default='*.txt')
file = open(direction,encoding='utf-8')
m = 'Documentation'+direction+' reads as follows: '
t = 'Open file'
te = ()
tb = (msg=m,title=t,text=te)
if te!=tb:
    The return value of the # textbox method is appended with a blank line
    reply = ('A change in the file has been detected, please select an action:',choices=['Overwrite save','Do not save','Save as...'])
    if reply=='Overwrite save':
        with open(direction,'w',encoding='utf-8') as file2:
            (tb)
    elif reply=='Save as...':
        # method, which returns the destination path and also sets the default value.
        file_site = (default='*.txt')
        with open(file_site,'w',encoding='utf-8') as file3:
            (tb)
()

To this article on the Python based EasyGUI learning practice of the article is introduced to this, more related Python EasyGUI content please search for my previous articles or continue to browse the following related articles I hope you will support me in the future!