用python编写导航界面,其中用到了wxpython模块

目录

简介:

源代码:

源代码说明:

效果如下所示:

待改进的地方:


简介:

由于写了很多python小程序,比较闪乱。为了以后用起来方便些,便于查找,今天看到一篇帖子有关wxpython编写界面的,试了一下能够实现功能,而其的界面比用到tkinter美观不少,才有了这篇博客。

源代码:

import wx
import os
import subprocess
class MyFrame(wx.Frame):
    def __init__(self, parent, title):
        super().__init__(parent, title=title, size=(800, 600))
        
        # 创建面板
        panel = wx.Panel(self)
        
        # 创建按钮
        btn1 = wx.Button(panel, label='找MP3', pos=(50, 50))
        btn2 = wx.Button(panel, label='4in1', pos=(150, 50))
        btn3 = wx.Button(panel, label='收邮件', pos=(250, 50))
        btn4 = wx.Button(panel, label='快截图', pos=(50, 100))
        btn5 = wx.Button(panel, label='看视频', pos=(150, 100))
        btn6 = wx.Button(panel, label='爬电影', pos=(250, 100))
        btn7 = wx.Button(panel, label='照片gps', pos=(50, 150))
        btn8 = wx.Button(panel, label='QR码', pos=(150, 150))
        btn9 = wx.Button(panel, label='随密', pos=(250, 150))
        btn10 = wx.Button(panel, label='上传', pos=(50, 200))
        btn11 = wx.Button(panel, label='监控', pos=(150, 200))
        btn12 = wx.Button(panel, label='切图', pos=(250, 200))
        
        # 绑定事件处理函数
        btn1.Bind(wx.EVT_BUTTON, self.onBtn1)
        btn2.Bind(wx.EVT_BUTTON, self.onBtn2)
        btn3.Bind(wx.EVT_BUTTON, self.onBtn3)
        btn4.Bind(wx.EVT_BUTTON, self.onBtn4)
        btn5.Bind(wx.EVT_BUTTON, self.onBtn5)
        btn6.Bind(wx.EVT_BUTTON, self.onBtn6)
        btn7.Bind(wx.EVT_BUTTON, self.onBtn7)
        btn8.Bind(wx.EVT_BUTTON, self.onBtn8)
        btn9.Bind(wx.EVT_BUTTON, self.onBtn9)
        btn10.Bind(wx.EVT_BUTTON, self.onBtn10)
        btn11.Bind(wx.EVT_BUTTON, self.onBtn11)
        btn12.Bind(wx.EVT_BUTTON, self.onBtn12)
        
        # 显示窗口
        self.Show()
        
    def onBtn1(self, event):
        subprocess.call(["python", "./finished/searchfolderforfile.py"])
        
    def onBtn2(self, event):
        subprocess.call(["python", "./finished/4in1.py"])
        
    def onBtn3(self, event):
         subprocess.call(["python", "./finished/autologinwebmail.py"])
        # subprocess.call(["python", "./autologinwebmail.py“])
        
    def onBtn4(self, event):
         subprocess.call(["python", "./finished/capturemp4.py"])
        
    def onBtn5(self, event):
        subprocess.call(["python", "./finished/searchMP4andSelectFileToPlay.py"])
        
    def onBtn6(self, event):
        subprocess.call(["python", "./finished/spiderofdouanmovies250.py"])
        
    def onBtn7(self, event):
        subprocess.call(["python", "./finished/jpegexifgps.py"])
        
    def onBtn8(self, event):
        subprocess.call(["python", "./finished/QRCodeGenertator.py"])
        
    def onBtn9(self, event):
        subprocess.call(["python", "./finished/randompasswordgenerator.py"])
        
    def onBtn10(self, event):
        subprocess.Popen(["python", "./uploadmobileapp.py"])
        
    def onBtn11(self, event):
        subprocess.Popen(["python", "./livecamapp.py"])
        
    def onBtn12(self, event):
        subprocess.call(["python", "./finished/cutimage4pics.py"])
        
if __name__ == '__main__':
    app = wx.App()
    frame = MyFrame(None, 'wxPython Demo')
    app.MainLoop()

源代码说明:

在这个示例代码中,我们创建了一个包含一个按钮的MyFrame窗口类,并在点击按钮时使用subprocess模块来运行service_program.py服务程序。您可以将subprocess.Popen函数的参数修改为您实际使用的服务程序的名称和路径。

请注意,在使用subprocess模块调用其他Python程序时,请确保两个程序之间没有任何死循环或无限循环,否则您可能需要手动中断程序。

效果如下所示:

待改进的地方:

调用flask模块生成的webservice容易报错。

猜你喜欢

转载自blog.csdn.net/winniezhang/article/details/129447680