利用wxpython完成对dialog对话框的实现

之前的脚本使用的是Apple script实现的,但是有小概率的情况下会出现无法运行(怀疑与用户的环境有关,不好调查),为了有一个“备胎”(最近华为的热门词“备胎”,借来用用),方便后续出现问题时,也能多一个选择。

这里先讲实现之前脚本的确认弹窗和隐私链接,后续再加入主程序。

#!/usr/local/bin/python3.6
# -*- coding: UTF-8 -*-
 

import wx
import wx.adv

class Complete(wx.Frame):

    def __init__(self, *args, **kwargs):
        super(Complete, self).__init__(*args, **kwargs)

        self.InitUI()


    def InitUI(self):


        wx.CallLater(500, self.ShowMessage)
        self.SetSize((350, 250))
        self.SetTitle('Window')
        self.Centre()


    def ShowMessage(self):
        dlg = wx.MessageBox('Files Remove Completed', 'Congratulations to you!',
            wx.OK | wx.CANCEL | wx.ICON_INFORMATION)
        if dlg == wx.CANCEL:
            self.OnAboutBox(True)

    def OnAboutBox(self, e):

    	description = """    Malware_Remove is a safe script, please feel free to use!
    	After double click this application, a Malware_removed Zip file will appear on your Desktop.
    	This tool will collect information to help us diagnose and fix the problem you are experiencing
    	with our product.
    	By sending us the report, you accept our Privacy Policy.
"""
    	licence = """Malware_remove is a free software;
"""
    	info = wx.adv.AboutDialogInfo()
    	info.SetIcon(wx.Icon('Malware_remove.png', wx.BITMAP_TYPE_PNG))
    	info.SetName('Malware_Remove')
    	info.SetVersion('1.0.0')
    	info.SetDescription(description)
    	info.SetCopyright('(C) 2019 - 2050 Julius luck')
    	info.SetWebSite('https://blog.csdn.net/julius_lee')
    	info.SetLicence(licence)
    	info.AddDeveloper('Julius luck')

    	wx.adv.AboutBox(info)

def main():

    app = wx.App()
    ex = Complete(None)
#    ex.ShowMessage()
#    ex.OnAboutBox(None)
    app.MainLoop()


if __name__ == '__main__':
    main()

输出的结果:

如果用户在第一个弹窗中选择了cancel,则会弹出about页面,上面展示了说明和隐私链接;点击 “OK”按钮,则直接完成,不需要二次弹窗。

这样,交互的内容基本上就完了,后续再考虑下如何结束整个程序,添加主程序的功能;

前面程序code的主要功能是:

1,使用了一个message 对话框,然后是一个about对话框

2,控件相关的选择可以有:

消息对话框即我们平时说的Messagebox,看看它的原型,下面是wxWidgets中的原型定义,C++风格,与python风格的区别就是wx前缀与后面名称直接相连,例如wxMessageDialog,在wxpython中使用时就是wx.MessageDialog

  wxMessageDialog(wxWindowparentconst wxStringmessageconst wxStringcaption = "Message box"long style = wxOK | wxCANCELconst wxPointpos = wxDefaultPosition)

  其各参数不多做介绍,主要看看ShowModal()方法,它使用应用程序在对话框关闭前不能响应其它窗口的用户事件,返回一个整数,取值如下:

  wx.ID_YES, wx.ID_NO, wx.ID_CANCEL, wx.ID_OK。

  另外,style的取值主要有以下几种:

wxOK Show an OK button.
wxCANCEL Show a Cancel button.
wxYES_NO Show Yes and No buttons.
wxYES_DEFAULT Used with wxYES_NO, makes Yes button the default - which is the default behaviour.
wxNO_DEFAULT Used with wxYES_NO, makes No button the default.
wxICON_EXCLAMATION Shows an exclamation mark icon.
wxICON_HAND Shows an error icon.
wxICON_ERROR Shows an error icon - the same as wxICON_HAND.
wxICON_QUESTION Shows a question mark icon.
wxICON_INFORMATION Shows an information (i) icon.
wxSTAY_ON_TOP The message box stays on top of all other window, even those of the other applications (Windows only). 

这个链接下对wxpython的用法写的比较详细,可以参考:

http://zetcode.com/

发布了192 篇原创文章 · 获赞 29 · 访问量 45万+

猜你喜欢

转载自blog.csdn.net/julius_lee/article/details/91045486