所有对话框包括:标准对话框、消息对话框、输入对话框等,如下图所示:
本实例对话框已封装成cyxLib.py文件,具体调用如下:
self.cyx=QcyxLib() #创建对象
消息对话框调用方法:messageDialog()
''' 参数说明: ===================================== 【消息框】参数val为字典类型,如: {"type":"information|warning|critical|question|about|Qt","title":"标题","text":"内容","button":"按钮 Yes|No"} 其中question有返回值Yes|No|Cancel,其它无返回值。 默认值:type=information,text="",title=提示,button=Yes|No ===================================== ''' #询问对话框 param={"type":"question","text":"文件已被修改,是否保存修改?"} #快速调用 #param={"type":"question","title":"文件变动提醒","text":"文件已被修改,是否保存修改?","button":"按钮 Yes|No|Cancel"} #完整参数调用 result=self.cyx.messageDialog(param) #返回值:Yes/No/Cancel print(result) #消息对话框 param={"text":"文件已经被正确打开"} self.cyx.messageDialog(param) #警告对话框 param={"type":"warning","text":"文件内容已经被修改"} self.cyx.messageDialog(param) #错误对话框 param={"type":"critical","text":"出现严重错误,程序将关闭。"} self.cyx.messageDialog(param) #关于对话框 strInfo="海南世云科技有限公司 @ 版权所有\n当前系统版本:V1.3.0\n官方网站:http://www.shiyunkj.com" param={"type":"about","text":strInfo} self.cyx.messageDialog(param) #Qt对话框 self.cyx.messageDialog({"type":"Qt"})
输入对话框调用方法:inputDialog()
''' 参数说明: ===================================== 【输入框】参数val为字典类型,如: {"type":"str|int|float|item|pwd","title":"标题","lable":"说明文字","value":"初始值"} 返回值:{"ok":True|False,"val":"返回输入/选择值"} 默认值:type=str,lable=请输入 ===================================== ''' #文字输入 param={"type":"str"} #快速调用 #param={"type":"str","title":"文字对话框","lable":"请输入姓名","value":"陈氏"} #完整参数调用 res=self.cyx.inputDialog(param) if(res["ok"]): print(res["val"]) #正数输入 param={"type":"int"} #快速调用 #param={"type":"int","title":"整数对话框","lable":"设置字体大小","value":0,"min":0,"max":100,"step":1} #完整参数调用 res=self.cyx.inputDialog(param) if(res["ok"]): print(res["val"]) #浮点数输入 param={"type":"float"} #快速调用 #param={"type":"float","title":"浮点数对话框","lable":"输入一个小数","value":2.38,"min":0.00,"max":100,"decimals":2} #完整参数调用 res=self.cyx.inputDialog(param) if(res["ok"]): text="输入一了个浮点数:%.2f"%res["val"] print(text) #选择框 items=["优秀","良好","一般","合格","不合格"] param={"type":"item","value":items} #快速调用 #param={"type":"item","title":"选择对话框","lable":"请选择级别","value":items,"index":0,"edit":False} #完整参数调用 res=self.cyx.inputDialog(param) if(res["ok"]): print("您选择的是:"+res["val"]) #密码输入 param={"type":"pwd"} #快速调用 #param={"type":"pwd","title":"密码对话框","lable":"请输入密码","value":"123456"} #完整参数调用 res=self.cyx.inputDialog(param) if(res["ok"]): print(res["val"])
文件对话框调用方法:fileDialog()
''' 参数说明: ===================================== 【文件框】参数val为字典类型,如: {"type":"single|multiple|directory|save","title":"标题","path":"默认打开路径","filt":"允许的文件类型"} 返回值:{"val":路径或文件名,"filt":"文件类型"} 默认值:type=single,title=对应对话框标题,path="",filt=所有文件(*.*) ===================================== ''' #单选文件框 param={"type":"single"} #快速调用 #param={"type":"single","title":"选择一个文件","path":"","filt":"图片文件(*.jpg *.png);;所有文件(*.*)"} #完整参数调用 res=self.cyx.fileDialog(param) print(res['val']+"\n"+res['filt']) #多选文件框 param={"type":"multiple"} #快速调用 #param={"type":"multiple","title":"选择多个文件","path":"","filt":"图片文件(*.jpg *.png);;所有文件(*.*)"} #完整参数调用 res=self.cyx.fileDialog(param) for i in range(len(res['val'])): print(res['val'][i]+"\n"+res['filt']) #目录选择框 param={"type":"directory"} #快速调用 #param={"type":"directory","title":"选择一个目录","path":""} #完整参数调用 res=self.cyx.fileDialog(param) print(res['val']) #保存文件框 param={"type":"save"} #快速调用 #param={"type":"save","title":"保存文件","path":"","filt":"所有文件(*.*);;文本文件(*.txt)"} #完整参数调用 res=self.cyx.fileDialog(param) print(res['val']+"\n"+res['filt'])
颜色对话框调用方法:colorDialog()
''' 参数说明: ===================================== 【颜色框】参数val为字典类型,如: {"title":"标题","value":"初始值"} 返回值:{"val":"object"} 默认值:title=选择颜色,value=黑色 ===================================== ''' res=self.cyx.colorDialog() #快速调用 #res=self.cyx.colorDialog({"title":"选择文字颜色","value":iniColor}) #完整参数调用 if res["val"].isValid(): print(res["val"])
字体对话框调用方法:fontDialog()
''' 参数说明: ===================================== 【字体框】参数val为字典类型,如: {"title":"标题","value":"初始值"} 返回值:{"ok":True|False,"val":"object"} 默认值:title=选择字体,value=微软雅黑,9 ===================================== ''' res=self.cyx.fontDialog() #快速调用 #res=self.cyx.fontDialog({"title":"选择文本内容字体","value":iniFont}) #完整参数调用 if(res["ok"]): print(res["val"])
进度条话框调用方法:progressDialog()
''' 参数说明: ===================================== 【进度框】参数val为字典类型,如: {"title":"标题","lable":"说明文字","min":"最小值 int","max":"最大值 int","button":"按钮名称","delay":"延迟 int"} 返回值:{"ok":True|False,"obj":进度对象值} 默认值:title=提示,lable=当前进度,min=0,max=100,button="取消",delay=50 注意:快慢由延迟时间决定,单位:秒,比如:最大值200,那么延迟时间可以设置成30秒。 ===================================== ''' #res=self.cyx.progressDialog() #快速调用 param={"title":"提示","lable":"当前复制进度","min":0,"max":500,"button":"取消","delay":10} res=self.cyx.progressDialog(param) #完整参数调用 if(res["ok"]): print("复制完成") else: print("***进度对话框被取消了***")
下一篇:PyQt5日期与时间 QDate, QTime, QDateTime
讨论数量:0