利用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/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章