之前的脚本使用的是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(wxWindow* parent, const wxString& message, const wxString& caption = "Message box", long style = wxOK | wxCANCEL, const wxPoint& pos = 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的用法写的比较详细,可以参考:
本文来自博客园,作者:{Julius},转载请注明原文链接:https://www.cnblogs.com/bestechshare/p/16447660.html
可微信加我,了解更多,WeChat:{KingisOK}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)