|
目录编辑easygui安装导入对话框1.消息框msgbox2.确认框ccbox3.布尔框boolbox4.是否框ynbox5.选择框choicebox6.整数输入框integerbox7.按钮选择框buttonbox8.单行文本框enterbox9. 多行文本框 textboxeasygui安装C:\>pipinstalleasyguiLookinginindexes:https://pypi.tuna.tsinghua.edu.cn/simpleCollectingeasygui Usingcachedhttps://pypi.tuna.tsinghua.edu.cn/packages/8e/a7/b276ff776533b423710a285c8168b52551cb2ab0855443131fdc7fd8c16f/easygui-0.98.3-py2.py3-none-any.whl(92kB)Installingcollectedpackages:easyguiSuccessfullyinstalledeasygui-0.98.3导入>>>importeasygui >>>easygui.__all__['buttonbox','diropenbox','fileopenbox','filesavebox','textbox','ynbox','ccbox','boolbox','indexbox','msgbox','integerbox','multenterbox','enterbox','exceptionbox','choicebox','codebox','passwordbox','multpasswordbox','multchoicebox','EgStore','eg_version','egversion','abouteasygui','egdemo']由以上列表,可以看到easygui共包含了19种对话框样式。对话框1.消息框msgboxmsgbox(msg='(Yourmessagegoeshere)',title='',ok_button='OK',image=None,root=None) The``msgbox()``functiondisplaysatextmessageandoffersanOK button.Themessagetextappearsinthecenterofthewindow,thetitle textappearsinthetitlebar,andyoucanreplacethe"OK"defaulttext onthebutton. :paramstrmsg:themsgtobedisplayed :paramstrtitle:thewindowtitle :paramstrok_button:texttoshowinthebutton :paramstrimage:Filenameofimagetodisplay :paramtk_widgetroot:Top-levelTkwidget :return:thetextoftheok_button显示文本消息并提供“确定”按钮。消息文本显示在窗口的中心,文本显示在栏中,可以替换按钮上的“确定”默认文本,例如:easygui.msgbox("备份完成!",title="结束",ok_button="干得好!")2.确认框ccboxccbox(msg='ShallIcontinue?',title='',choices=('C[o]ntinue','C[a]ncel'),image=None,default_choice='Continue',cancel_choice='Cancel')The``ccbox()``functionoffersachoiceofContinueandCancel,andreturnseitherTrue(for continue)orFalse(forcancel). :paramstrmsg:themsgtobedisplayed :paramstrtitle:thewindowtitle :paramlistchoices:alistortupleofthechoicestobedisplayed :paramstrimage:Filenameofimagetodisplay :paramstrdefault_choice:Thechoiceyouwanthighlighted whentheguiappears :paramstrcancel_choice:Iftheuserpressesthe'X'close, whichbuttonshouldbepressed :return:Trueif'Continue'ordialogiscancelled,Falseif'Cancel'提供了“继续”和“取消”选项,并返回True(表示继续)或False(表示取消)。默认的按钮文本为:'Continue'和'Cancel',也可以使用按钮文本自定义,例如: easygui.ccbox(msg,title,choices=('退出[E]','取消[C]'))3.布尔框boolboxboolbox(msg='ShallIcontinue?',title='',choices=('[T]rue','[F]alse'),image=None,default_choice='[T]rue',cancel_choice='[F]alse') The``boolbox()``(booleanbox)displaystwobuttons.Returnsreturns``True``ifthefirstbuttonischosen.Otherwisereturns``False``. :paramstrmsg:Themessageshowninthecenterofthedialogwindow. :paramstrtitle:Thewindowtitletext. :paramlistchoices:Alistortupleofstringsforthebuttons'text. :paramstrimage:Thefilenameofanimagetodisplayinthedialogwindow. :paramstrdefault_choice:Thetextofthedefaultselectedbutton. :paramstrcancel_choice:Iftheuserpressesthe'X'close,whichbuttonshouldbepressed :return:`True`iffirstbuttonpressedordialogiscancelled,`False` ifsecondbuttonispressed.如果选择了第一个按钮,则返回“True”。否则返回“False”。与msgbox的联用,代码如下: importeasyguimessage="Whatdotheysay?"title="RomanticQuestion"ifeasygui.boolbox(message,title,["Theyloveme","Theylovemenot"]):easygui.msgbox('Youshouldsendthemflowers.')else:easygui.msgbox('Itwasnotmeanttobe.')4.是否框ynboxynbox(msg='ShallIcontinue?',title='',choices=('[]Yes','[]No'),image=None,default_choice='[]Yes',cancel_choice='[]No') :parammsg:themsgtobedisplayed :typemsg:str :paramstrtitle:thewindowtitle :paramlistchoices:alistortupleofthechoicestobedisplayed :paramstrimage:Filenameofimagetodisplay :paramstrdefault_choice:Thechoiceyouwanthighlightedwhentheguiappears :paramstrcancel_choice:Iftheuserpressesthe'X'close,whichbuttonshouldbepressed :return:Trueif'Yes'ordialogiscancelled,Falseif'No'提供了Yes和No的选择,并返回“True”或“False”。importeasyguiresult=easygui.ynbox('Isahotdogasandwich?','HotDogQuestion')ifresult==True:easygui.msgbox('Thatisaninterestinganswer.')else:easygui.msgbox('Well,thatisyouropinion.')5.选择框choiceboxchoicebox(msg='Pickanitem',title='',choices=None,preselect=0,callback=None,run=True) The``choicebox()``providesalistofchoicesinalistboxtochoosefrom.Thechoicesarespecifiedinasequence(atupleoralist). :paramstrmsg:themsgtobedisplayed :paramstrtitle:thewindowtitle :paramlistchoices:alistortupleofthechoicestobedisplayed :parampreselect:Whichitem,ifanyarepreselectedwhendialogappears :return:AstringoftheselectedchoiceorNoneifcancelled在列表框中提供了可供选择的由元组或列表指定的选项列表。importeasyguimsg="Whatisyourfavoriteflavor?"title="IceCreamSurvey"choices=["Vanilla","Chocolate","Strawberry","CoffeeLatte"]choice=easygui.choicebox(msg,title,choices)#choiceisastringprint(choice)注:选择“Chocolate”后点OK就把所选择的项赋值给变量choice,点Cancel则返回None。6.整数输入框integerboxintegerbox(msg='',title='',default=None,lowerbound=0,upperbound=99,image=None,root=None) Showaboxinwhichausercanenteraninteger. Inadditiontoargumentsformsgandtitle,thisfunctionaccepts integerargumentsfor"default","lowerbound",and"upperbound". Thedefault,lowerbound,orupperboundmaybeNone. Whentheuserenterssometext,thetextischeckedtoverifythatitcanbeconvertedtoanintegerbetweenthelowerboundandupperbound. Ifitcanbe,theinteger(notthetext)isreturned. Ifitcannot,thenanerrormsgisdisplayed,andtheintegerboxisredisplayed. Iftheusercancelstheoperation,Noneisreturned. :paramstrmsg:themsgtobedisplayed :paramstrtitle:thewindowtitle :paramintdefault:Thedefaultvaluetoreturn :paramintlowerbound:Thelower-mostvalueallowed :paramintupperbound:Theupper-mostvalueallowed :paramstrimage:Filenameofimagetodisplay :paramtk_widgetroot:Top-levelTkwidget :return:theintegervalueenteredbytheuser显示一个框,用户可以在其中输入整数。除了msg和title的参数外,此函数还接受“default”、“lowerbound”和“upperfound”的整数参数。默认值、下限值或上限值可能为“None”。当用户输入一些文本时,会检查文本以验证它是否可以转换为介于下限和上限之间的整数。如果可以,则返回整数(而不是文本)。如果不能,则会显示一条错误消息,并重新显示integebox。如果用户取消操作,则返回None。importeasyguiresult=easygui.integerbox('请输入一个整数:')print(result)注:输入整数超出上下限或输入的不是一个整数,返回一个msgbox:7.按钮选择框buttonboxbuttonbox(msg='',title='',choices=('Button[1]','Button[2]','Button[3]'),image=None,images=None,default_choice=None,cancel_choice=None,callback=None,run=True) Displayamessage,atitle,animage,andasetofbuttons. Thebuttonsaredefinedbythemembersofthechoicesargument. :paramstrmsg:themsgtobedisplayed :paramstrtitle:thewindowtitle :paramlistchoices:alistortupleofthechoicestobedisplayed :paramstrimageOnlyhereforbackwardcompatibility) :paramstrimages:Filenameofimageoriterableoriteratableofiterabletodisplay :paramstrdefault_choice:Thechoiceyouwanthighlightedwhentheguiappears :return:thetextofthebuttonthattheuserselected显示多个按钮,按钮由参数choices的元组来定义,按钮的个数取决于元组的元素个数。importeasyguiasegeg.buttonbox(msg='请选择:',title='自定义确认框',choices=('浏览...','确定','取消'),image=None,images=None,default_choice="确定",cancel_choice=None,callback=None,run=True)8.单行文本框enterboxenterbox(msg='Entersomething.',title='',default='',strip=True,image=None,root=None) Showaboxinwhichausercanentersometext. Youmayoptionallyspecifysomedefaulttext,whichwillappearinthenterboxwhenitisdisplayed. :paramstrmsg:themsgtobedisplayed. :paramstrtitle:thewindowtitle :paramstrdefault:valuereturnedifuserdoesnotchangeit :paramboolstrip:IfTrue,thereturnvaluewillhaveitswhitespacestrippedbeforebeingreturned :return:thetextthattheuserentered,orNoneiftheycanceltheoperation.显示一个框,用户可以在其中输入一些文本。您可以选择指定一些默认文本显示时显示在对话框中,如下图:importeasyguiasegreply=eg.enterbox('请输入车牌号:','单行文本框',default='例如:苏ENH905')ifreply:eg.msgbox(f'你的输入为:{reply}')else:eg.msgbox('输入为空,或者点了取消Cancel')9. 多行文本框 textboxtextbox(msg='',title='',text='',codebox=False,callback=None,run=True)Displaysadialogboxwithalarge,multi-linetextbox,andreturns theenteredtextasastring.Themessagetextisdisplayedina proportionalfontandwraps.  arameters ---------- msg:string textdisplayedinthemessagearea(instructions...) title:str thewindowtitle text:str,listortuple textdisplayedintextAreas(editable) codebox:bool ifTrue,don'twrapandwidthissetto80chars callback:function ifset,thisfunctionwillbecalledwhenOKispressed run:bool ifTrue,aboxobjectwillbecreatedandreturned,butnotrun Returns ------- None Ifcancelispressed str IfOKispressedreturnsthecontentsoftextArea 显示一个带有多行文本框的对话框,并将输入的文本作为字符串返回。例如:importeasyguiasegtxt='''一、基本信息 姓名:XX 性别:X 年龄:X 婚姻状况:XX 毕业院校:XX 联系电话:XXXXXXXXXXX二、求职意向 意向岗位:XXXX 证书:XXX 薪资要求:面议 工作能力及专长:本人有一定的......。三、工作经历 XXXX年X月~XXXX年X月,......。 XXXX年X月~XXXX年X月,......。四、自我评价 本人对工作......'''reply=eg.textbox(msg='请按以下模板输入你的简历:',title='简历',text=txt,codebox=False,callback=None,run=True)print(reply)待续......
|
|