使用wx制作一个桌面软件

news/2024/11/18 17:20:29/文章来源:https://www.cnblogs.com/xuxiaobo/p/18349077

前面因为抓取数据,为了方便期间做了各界面,用到了wx,觉得很好用,所以最近几天专门看了一下wx的使用,并练习了一下。

代码:

import os,sys,re,time
import wx,wx.xrc,wx.adv,wx.grid
import json,math,random
import subprocess,threading
from win32api import GetSystemMetrics
from faker import FakerAPP_ICON = '.\\favicon_test2.ico'
APP_TITLE = '测试软件'
nowtime1 = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
nowtime2 = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
nowunixtime = int(round(time.time() * 1000))
username = ''
password = ''
percent = 0.6
faker = Faker(locale='zh_CN')
show_icon = False
show_window = True
myFrames = {}
myFrame = ''abouttext = '''
import wxclass MyFrame(wx.Frame):def __init__(self, parent):wx.Frame.__init__(self, parent, -1, "多行文本框示例")panel = wx.Panel(self)# 创建多行文本框self.multi_text_ctrl = wx.TextCtrl(panel, style=wx.TE_MULTILINE)# 设置布局管理器sizer = wx.BoxSizer(wx.VERTICAL)sizer.Add(self.multi_text_ctrl, 1, wx.ALL|wx.EXPAND, 5)panel.SetSizer(sizer)if __name__ == "__main__":app = wx.App(False)frame = MyFrame(None)frame.Show(True)app.MainLoop()
'''.strip()datas = []
for i in range(0, 1017):sex = random.randint(0,1)if sex == 0:name = faker.name_male()sex2 = '男'else:name = faker.name_female()sex2 = '女'datas.append([name,sex2,str(random.randint(1,99)),faker.email(),faker.company(),faker.address()])labelSize = (int(90*percent), int(45*percent))
textSize = (int(250*percent), int(45*percent))
buttonSize = (int(110*percent), int(45*percent))
imgSize = (int(1024*percent), int(768*percent))
lineHeight = int(45*percent)def getFileContent(file):fp = open(file, 'r', encoding='utf-8')res = fp.read()fp.close()return resdef saveFileContent(file, content):fp = open(file, 'w', encoding='utf-8')fp.write(content)fp.close()class FolderBookmarkTaskBarIcon(wx.adv.TaskBarIcon):MENU_ID1, MENU_ID2 = wx.NewIdRef(count=2)def __init__(self):super().__init__()self.SetIcon(wx.Icon(APP_ICON), APP_TITLE)self.Bind(wx.EVT_MENU, self.onShow, id=self.MENU_ID1)self.Bind(wx.EVT_MENU, self.onExit, id=self.MENU_ID2)def CreatePopupMenu(self):menu = wx.Menu()menu.Append(self.MENU_ID1, '显示隐藏')menu.Append(self.MENU_ID2, '退出')return menudef onShow(self, event):global show_window,myFrames,myFrameframe = myFrames[myFrame]if show_window == True:frame.Show(False)show_window = Falseelse:frame.Show(True)show_window = Truedef onExit(self, event):wx.Exit()class LoginFrame ( wx.Frame):sub_title = '登录'my_frame = 'login'def __init__( self, parent ):global percent,labelSize,textSize,buttonSize,lineHeight,username,show_window,myFrames,myFrame,show_iconwx.Frame.__init__ ( self, parent, id = wx.ID_ANY, style = wx.DEFAULT_FRAME_STYLE )labelFont = wx.Font(int(18*percent), wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)labelColor = wx.Colour( 139, 69, 19 )#设置窗口位置,大小screen_width = GetSystemMetrics(0)screen_height = GetSystemMetrics(1)window_width = int(screen_width*percent)window_height = int(screen_height*percent)self.SetSize((window_width, window_height))position_x = (screen_width - window_width) // 2position_y = (screen_height - window_height) // 2self.SetPosition(wx.Point(position_x, position_y))#计算控件坐标positionx_label = (window_width - (labelSize[0] + textSize[0])) // 2positionx_text = positionx_label + labelSize[0]positionx_button = positionx_text + textSize[0] - buttonSize[0]positiony_label1 = (window_height - (labelSize[1]*3 + lineHeight*2)) // 2positiony_label2 = positiony_label1 + labelSize[1] + lineHeightpositiony_label3 = positiony_label1 + labelSize[1] + lineHeight + labelSize[1] + lineHeightself.usernameLabel = wx.StaticText(self, label='用户名:', size=labelSize)self.usernameLabel.SetPosition(wx.Point(positionx_label, positiony_label1))self.usernameLabel.SetFont(labelFont)self.usernameLabel.SetForegroundColour(labelColor)self.usernameInput = wx.TextCtrl(self, size=textSize)self.usernameInput.SetPosition(wx.Point(positionx_text, positiony_label1))self.usernameInput.SetValue("admin")self.passwordLabel = wx.StaticText(self, label='密码:', size=labelSize)self.passwordLabel.SetPosition(wx.Point(positionx_label, positiony_label2))self.passwordLabel.SetFont(labelFont)self.passwordLabel.SetForegroundColour(labelColor)self.passwordInput = wx.TextCtrl(self, style=wx.TE_PASSWORD, size=textSize)self.passwordInput.SetPosition(wx.Point(positionx_text, positiony_label2))self.passwordInput.SetValue("123456")self.loginButton = wx.Button( self, label='登录', size=buttonSize)self.loginButton.SetPosition(wx.Point(positionx_button, positiony_label3))self.loginButton.SetFont(labelFont)self.loginButton.SetForegroundColour(labelColor)self.loginButton.Bind( wx.EVT_BUTTON, self.login )self.SetWindowStyle(wx.STAY_ON_TOP | wx.CAPTION | wx.SYSTEM_MENU)self.SetTitle(APP_TITLE+'-'+self.sub_title)self.SetIcon(wx.Icon(APP_ICON))self.SetBackgroundColour( wx.Colour( 245, 222, 179 ) )self.Raise()self.Show(True)show_window = TruemyFrame = self.my_frameif not myFrame in myFrames:myFrames[myFrame] = self#显示iconif show_icon == False:FolderBookmarkTaskBarIcon()show_icon = True#绑定事件self.timer = wx.Timer(self)self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)self.timer.Start(3000)def OnTimer(self, event):thread_obj = threading.Thread(target=self.OnTimer1, args=(event, ))thread_obj.start()def OnTimer1(self, event):#设置窗口位置,大小return ;screen_width = GetSystemMetrics(0)screen_height = GetSystemMetrics(1)print('屏幕大小: %s*%s' % (screen_width, screen_height))(window_widthx, window_heightx) = self.GetSize()print('窗口大小: %s*%s' % (window_widthx, window_heightx))(position_xx, position_yy) = self.GetPosition()print('窗口位置: %s*%s' % (position_xx, position_yy))print()def login(self, event):global username, passwordusernameVal = self.usernameInput.GetValue()passwordVal = self.passwordInput.GetValue()if not usernameVal in ['admin', 'root'] or passwordVal != '123456':wx.MessageBox('用户名和密码不匹配')return Falseusername = usernameValpassword = passwordValself.Hide()mfObj = MainFrame(None)return Truedef __del__( self ):passclass MainFrame ( wx.Frame):sub_title = '首页'my_frame = 'main'def __init__( self, parent ):global percent,labelSize,textSize,buttonSize,imgSize,lineHeight,username,show_window,myFrames,myFramewx.Frame.__init__ ( self, parent, id = wx.ID_ANY, style = wx.DEFAULT_FRAME_STYLE )labelFont = wx.Font(int(18*percent), wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)labelColor = wx.Colour( 139, 69, 19 )#设置窗口位置,大小screen_width = GetSystemMetrics(0)screen_height = GetSystemMetrics(1)window_width = int(screen_width*percent)window_height = int(screen_height*percent)self.SetSize((window_width, window_height))position_x = (screen_width - window_width) // 2position_y = (screen_height - window_height) // 2self.SetPosition(wx.Point(position_x, position_y))labelSize = (int(310*percent), int(25*percent))positionx_label1 = int(5*percent)positiony_label1 = int(5*percent)positionx_label2 = window_width - labelSize[0]positiony_label2 = int(5*percent)self.usernameLabel = wx.StaticText(self, label='', size=labelSize)self.usernameLabel.SetPosition(wx.Point(positionx_label1, positiony_label1))self.usernameLabel.SetFont(labelFont)self.usernameLabel.SetForegroundColour(labelColor)if username == '':username = '未知用户'self.usernameLabel = wx.StaticText(self, label='登录用户:'+username, size=labelSize)self.usernameLabel.SetPosition(wx.Point(positionx_label2, positiony_label2))self.usernameLabel.SetFont(labelFont)self.usernameLabel.SetForegroundColour(labelColor)if not username == '未知用户':self.usernameLabel.Bind( wx.EVT_LEFT_DOWN, self.logout )positionx_label3 = (window_width - buttonSize[0]) // 2positiony_label3 = window_height - int(150*percent)self.SelBtn = wx.Button(self, label='选择图片', size=buttonSize)self.SelBtn.SetPosition(wx.Point(positionx_label3, positiony_label3))self.SelBtn.Bind(wx.EVT_BUTTON, self.OnChooseFile)self.SelBtn.SetFont(labelFont)self.SelBtn.SetForegroundColour(labelColor)positionx_label4 = (window_width - imgSize[0]) // 2positiony_label4 = (window_height - imgSize[1] - labelSize[1] - buttonSize[1]) // 2self.image_ctrl = wx.StaticBitmap(self, size=imgSize)self.image_ctrl.SetPosition(wx.Point(positionx_label4, positiony_label4))#添加菜单self.appendmenus()self.SetWindowStyle(wx.STAY_ON_TOP | wx.CAPTION | wx.SYSTEM_MENU)self.SetTitle(APP_TITLE+'-'+self.sub_title)self.SetIcon(wx.Icon(APP_ICON))self.SetBackgroundColour( wx.Colour( 245, 222, 179 ) )self.Raise()self.Show(True)show_window = TruemyFrame = self.my_frameif not myFrame in myFrames:myFrames[myFrame] = self#绑定事件self.timer = wx.Timer(self)self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)self.timer.Start(3000)def OnChooseFile(self, event):global imgSizewildcard = 'All files(*.jpg)|*.jpg|*.png|*.gif'dialog = wx.FileDialog(None,'select',os.getcwd(),'',wildcard,wx.FD_OPEN)if dialog.ShowModal() == wx.ID_OK:fileName = dialog.GetPath()image = wx.Image(fileName, wx.BITMAP_TYPE_ANY)image.Rescale(imgSize[0], imgSize[1], wx.IMAGE_QUALITY_NORMAL)self.image_ctrl.SetBitmap(wx.Bitmap(image))dialog.Destroy()def appendmenus(self):menu_bar = wx.MenuBar()gongneng_menu = wx.Menu()guanyu_menu = wx.Menu()index_item = gongneng_menu.Append(-1, "&首页", "返回首页")user_item1 = gongneng_menu.Append(-1, "&用户列表", "查看用户信息")tree_item1 = gongneng_menu.Append(-1, "&展示树", "查看树形结构")about_item = guanyu_menu.Append(-1, "&关于我们", "关于我们")self.Bind(wx.EVT_MENU, self.toindex, index_item)self.Bind(wx.EVT_MENU, self.touserlist, user_item1)self.Bind(wx.EVT_MENU, self.totree, tree_item1)self.Bind(wx.EVT_MENU, self.toabout, about_item)menu_bar.Append(gongneng_menu, "&功能")menu_bar.Append(guanyu_menu, "&关于")self.SetMenuBar(menu_bar)def logout(self, event):global username, passworddlg = wx.MessageDialog(None, '确认退出吗?', '用户确认', wx.YES_NO)result = dlg.ShowModal()if result == wx.ID_YES:username = ''password = ''self.tologin(event)else:passdlg.Destroy()return Truedef tologin(self, event):global myFrames,show_window,myFrameself.Hide()myFrame = 'login'if myFrame in myFrames:mfObj = myFrames[myFrame]mfObj.Show(True)show_window = Trueelse:mfObj = MainFrame(None)show_window = Truedef toindex(self, event):global myFrames,show_window,myFrameself.Hide()myFrame = 'main'if myFrame in myFrames:mfObj = myFrames[myFrame]mfObj.Show(True)show_window = Trueelse:mfObj = MainFrame(None)show_window = Truedef touserlist(self, event):global myFrames,show_window,myFrameself.Hide()myFrame = 'user'if myFrame in myFrames:mfObj = myFrames[myFrame]mfObj.Show(True)show_window = Trueelse:mfObj = UserFrame(None)show_window = Truedef totree(self, event):global myFrames,show_window,myFrameself.Hide()myFrame = 'tree'if myFrame in myFrames:mfObj = myFrames[myFrame]mfObj.Show(True)show_window = Trueelse:mfObj = TreeFrame(None)show_window = Truedef toabout(self, event):global myFrames,show_window,myFrameself.Hide()myFrame = 'about'if myFrame in myFrames:mfObj = myFrames[myFrame]mfObj.Show(True)show_window = Trueelse:mfObj = AboutFrame(None)show_window = Truedef OnTimer(self, event):thread_obj = threading.Thread(target=self.OnTimer1, args=(event, ))thread_obj.start()def OnTimer1(self, event):passdef __del__( self ):passclass UserFrame ( wx.Frame):sub_title = '用户列表'my_frame = 'user'page = 1pagesize = 50def __init__( self, parent ):global percent,labelSize,textSize,buttonSize,lineHeight,username,show_window,myFrames,myFramewx.Frame.__init__ ( self, parent, id = wx.ID_ANY, style = wx.DEFAULT_FRAME_STYLE )labelFont = wx.Font(int(18*percent), wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)labelColor = wx.Colour( 139, 69, 19 )#设置窗口位置,大小screen_width = GetSystemMetrics(0)screen_height = GetSystemMetrics(1)window_width = int(screen_width*percent)window_height = int(screen_height*percent)self.SetSize((window_width, window_height))position_x = (screen_width - window_width) // 2position_y = (screen_height - window_height) // 2self.SetPosition(wx.Point(position_x, position_y))labelSize = (int(310*percent), int(25*percent))positionx_label1 = int(5*percent)positiony_label1 = int(5*percent)positionx_label2 = window_width - labelSize[0]positiony_label2 = int(5*percent)self.usernameLabel = wx.StaticText(self, label='', size=labelSize)self.usernameLabel.SetPosition(wx.Point(positionx_label1, positiony_label1))self.usernameLabel.SetFont(labelFont)self.usernameLabel.SetForegroundColour(labelColor)if username == '':username = '未知用户'self.usernameLabel = wx.StaticText(self, label='登录用户:'+username, size=labelSize)self.usernameLabel.SetPosition(wx.Point(positionx_label2, positiony_label2))self.usernameLabel.SetFont(labelFont)self.usernameLabel.SetForegroundColour(labelColor)if not username == '未知用户':self.usernameLabel.Bind( wx.EVT_LEFT_DOWN, self.logout )self.showGridData(self.page)positionx_label4 = int(5*percent)positiony_label4 = int(930*percent)self.preButton = wx.Button( self, label='上一页', size=buttonSize)self.preButton.SetPosition(wx.Point(positionx_label4, positiony_label4))self.preButton.SetFont(labelFont)self.preButton.SetForegroundColour(labelColor)self.preButton.Bind( wx.EVT_BUTTON, self.showGridDataPre )positionx_label5 = int(160*percent)positiony_label5 = int(930*percent)self.nextButton = wx.Button( self, label='下一页', size=buttonSize)self.nextButton.SetPosition(wx.Point(positionx_label5, positiony_label5))self.nextButton.SetFont(labelFont)self.nextButton.SetForegroundColour(labelColor)self.nextButton.Bind( wx.EVT_BUTTON, self.showGridDataNext )#添加菜单self.appendmenus()self.SetWindowStyle(wx.STAY_ON_TOP | wx.CAPTION | wx.SYSTEM_MENU)self.SetTitle(APP_TITLE+'-'+self.sub_title)self.SetIcon(wx.Icon(APP_ICON))self.SetBackgroundColour( wx.Colour( 245, 222, 179 ) )self.Raise()self.Show(True)show_window = TruemyFrame = self.my_frameif not myFrame in myFrames:myFrames[myFrame] = self#绑定事件self.timer = wx.Timer(self)self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)self.timer.Start(3000)def appendmenus(self):menu_bar = wx.MenuBar()gongneng_menu = wx.Menu()guanyu_menu = wx.Menu()index_item = gongneng_menu.Append(-1, "&首页", "返回首页")user_item1 = gongneng_menu.Append(-1, "&用户列表", "查看用户信息")tree_item1 = gongneng_menu.Append(-1, "&展示树", "查看树形结构")about_item = guanyu_menu.Append(-1, "&关于我们", "关于我们")self.Bind(wx.EVT_MENU, self.toindex, index_item)self.Bind(wx.EVT_MENU, self.touserlist, user_item1)self.Bind(wx.EVT_MENU, self.totree, tree_item1)self.Bind(wx.EVT_MENU, self.toabout, about_item)menu_bar.Append(gongneng_menu, "&功能")menu_bar.Append(guanyu_menu, "&关于")self.SetMenuBar(menu_bar)def showGridDataPre(self, event):global datasself.page = self.page - 1totalpage = math.ceil(len(datas) / (self.pagesize + 0.00))if self.page < 1:self.page = 1if self.page > totalpage:self.page = totalpageself.showGridData(self.page)def showGridDataNext(self, event):global datasself.page = self.page + 1totalpage = math.ceil(len(datas) / (self.pagesize + 0.00))if self.page < 1:self.page = 1if self.page > totalpage:self.page = totalpageself.showGridData(self.page)def showGridData(self, page):try:self.grid.Destroy()except:passlabelFont = wx.Font(int(18*percent), wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)gridSize = (int(1880*percent), int(885*percent))positionx_label3 = int(5*percent)positiony_label3 = int(30*percent)self.grid = wx.grid.Grid(self, size=gridSize)self.grid.SetPosition(wx.Point(positionx_label3, positiony_label3))self.grid.SetFont(labelFont)self.grid.SetRowLabelSize(25)  # 设置行标签的宽度self.grid.SetColLabelSize(25)  # 设置列标签的宽度self.grid.SetColLabelValue(0, "姓名")self.grid.SetColLabelValue(1, "性别")self.grid.SetColLabelValue(2, "年龄")self.grid.SetColLabelValue(3, "邮箱")self.grid.SetColLabelValue(4, "公司")self.grid.SetColLabelValue(5, "地址")cellColor = wx.Colour( 240, 255, 255 )data = self.getData(page)self.grid.CreateGrid(len(data), len(data[0]))for row in range(len(data)):for col in range(len(data[row])):self.grid.SetCellValue(row, col, data[row][col])self.grid.SetCellBackgroundColour(row, col, cellColor)if col in [0,1,2]:self.grid.SetColSize(col, int(215*percent))elif col in [3]:self.grid.SetColSize(col, int(350*percent))elif col in [4]:self.grid.SetColSize(col, int(350*percent))elif col in [5]:self.grid.SetColSize(col, int(500*percent))def getData(self, page):global datastotalpage = math.ceil(len(datas) / (self.pagesize + 0.00))if page < 1:page = 1if page > totalpage:page = totalpagestart = (page - 1) * self.pagesizeend = start + self.pagesizeresdata = []for i,data in enumerate(datas):if i>= start and i<end:resdata.append(data)return resdatadef logout(self, event):global username, passworddlg = wx.MessageDialog(None, '确认退出吗?', '用户确认', wx.YES_NO)result = dlg.ShowModal()if result == wx.ID_YES:username = ''password = ''self.tologin(event)else:passdlg.Destroy()return Truedef tologin(self, event):global myFrames,show_window,myFrameself.Hide()myFrame = 'login'if myFrame in myFrames:mfObj = myFrames[myFrame]mfObj.Show(True)show_window = Trueelse:mfObj = MainFrame(None)show_window = Truedef toindex(self, event):global myFrames,show_window,myFrameself.Hide()myFrame = 'main'if myFrame in myFrames:mfObj = myFrames[myFrame]mfObj.Show(True)show_window = Trueelse:mfObj = MainFrame(None)show_window = Truedef touserlist(self, event):global myFrames,show_window,myFrameself.Hide()myFrame = 'user'if myFrame in myFrames:mfObj = myFrames[myFrame]mfObj.Show(True)show_window = Trueelse:mfObj = UserFrame(None)show_window = Truedef totree(self, event):global myFrames,show_window,myFrameself.Hide()myFrame = 'tree'if myFrame in myFrames:mfObj = myFrames[myFrame]mfObj.Show(True)show_window = Trueelse:mfObj = TreeFrame(None)show_window = Truedef toabout(self, event):global myFrames,show_window,myFrameself.Hide()myFrame = 'about'if myFrame in myFrames:mfObj = myFrames[myFrame]mfObj.Show(True)show_window = Trueelse:mfObj = AboutFrame(None)show_window = Truedef OnTimer(self, event):thread_obj = threading.Thread(target=self.OnTimer1, args=(event, ))thread_obj.start()def OnTimer1(self, event):passdef __del__( self ):passclass AboutFrame ( wx.Frame):sub_title = '关于我们'my_frame = 'about'def __init__( self, parent ):global percent,labelSize,textSize,buttonSize,lineHeight,username,abouttext,show_window,myFrames,myFramewx.Frame.__init__ ( self, parent, id = wx.ID_ANY, style = wx.DEFAULT_FRAME_STYLE )labelFont = wx.Font(int(18*percent), wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)labelColor = wx.Colour( 139, 69, 19 )#设置窗口位置,大小screen_width = GetSystemMetrics(0)screen_height = GetSystemMetrics(1)window_width = int(screen_width*percent)window_height = int(screen_height*percent)self.SetSize((window_width, window_height))position_x = (screen_width - window_width) // 2position_y = (screen_height - window_height) // 2self.SetPosition(wx.Point(position_x, position_y))labelSize = (int(310*percent), int(25*percent))positionx_label1 = int(5*percent)positiony_label1 = int(5*percent)positionx_label2 = window_width - labelSize[0]positiony_label2 = int(5*percent)self.usernameLabel = wx.StaticText(self, label='', size=labelSize)self.usernameLabel.SetPosition(wx.Point(positionx_label1, positiony_label1))self.usernameLabel.SetFont(labelFont)self.usernameLabel.SetForegroundColour(labelColor)if username == '':username = '未知用户'self.usernameLabel = wx.StaticText(self, label='登录用户:'+username, size=labelSize)self.usernameLabel.SetPosition(wx.Point(positionx_label2, positiony_label2))self.usernameLabel.SetFont(labelFont)self.usernameLabel.SetForegroundColour(labelColor)if not username == '未知用户':self.usernameLabel.Bind( wx.EVT_LEFT_DOWN, self.logout )textSize1 = (int(1880*percent), int(945*percent))positionx_label3 = int(8*percent)positiony_label3 = int(30*percent)self.usernameInput = wx.TextCtrl(self, style=wx.TE_MULTILINE, size=textSize1)self.usernameInput.SetPosition(wx.Point(positionx_label3, positiony_label3))self.usernameInput.SetValue(abouttext)#添加菜单self.appendmenus()self.SetWindowStyle(wx.STAY_ON_TOP | wx.CAPTION | wx.SYSTEM_MENU)self.SetTitle(APP_TITLE+'-'+self.sub_title)self.SetIcon(wx.Icon(APP_ICON))self.SetBackgroundColour( wx.Colour( 245, 222, 179 ) )self.Raise()self.Show(True)show_window = TruemyFrame = self.my_frameif not myFrame in myFrames:myFrames[myFrame] = self#绑定事件self.timer = wx.Timer(self)self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)self.timer.Start(3000)def appendmenus(self):menu_bar = wx.MenuBar()gongneng_menu = wx.Menu()guanyu_menu = wx.Menu()index_item = gongneng_menu.Append(-1, "&首页", "返回首页")user_item1 = gongneng_menu.Append(-1, "&用户列表", "查看用户信息")tree_item1 = gongneng_menu.Append(-1, "&展示树", "查看树形结构")about_item = guanyu_menu.Append(-1, "&关于我们", "关于我们")self.Bind(wx.EVT_MENU, self.toindex, index_item)self.Bind(wx.EVT_MENU, self.touserlist, user_item1)self.Bind(wx.EVT_MENU, self.totree, tree_item1)self.Bind(wx.EVT_MENU, self.toabout, about_item)menu_bar.Append(gongneng_menu, "&功能")menu_bar.Append(guanyu_menu, "&关于")self.SetMenuBar(menu_bar)def logout(self, event):global username, passworddlg = wx.MessageDialog(None, '确认退出吗?', '用户确认', wx.YES_NO)result = dlg.ShowModal()if result == wx.ID_YES:username = ''password = ''self.tologin(event)else:passdlg.Destroy()return Truedef tologin(self, event):global myFrames,show_window,myFrameself.Hide()myFrame = 'login'if myFrame in myFrames:mfObj = myFrames[myFrame]mfObj.Show(True)show_window = Trueelse:mfObj = MainFrame(None)show_window = Truedef toindex(self, event):global myFrames,show_window,myFrameself.Hide()myFrame = 'main'if myFrame in myFrames:mfObj = myFrames[myFrame]mfObj.Show(True)show_window = Trueelse:mfObj = MainFrame(None)show_window = Truedef touserlist(self, event):global myFrames,show_window,myFrameself.Hide()myFrame = 'user'if myFrame in myFrames:mfObj = myFrames[myFrame]mfObj.Show(True)show_window = Trueelse:mfObj = UserFrame(None)show_window = Truedef totree(self, event):global myFrames,show_window,myFrameself.Hide()myFrame = 'tree'if myFrame in myFrames:mfObj = myFrames[myFrame]mfObj.Show(True)show_window = Trueelse:mfObj = TreeFrame(None)show_window = Truedef toabout(self, event):global myFrames,show_window,myFrameself.Hide()myFrame = 'about'if myFrame in myFrames:mfObj = myFrames[myFrame]mfObj.Show(True)show_window = Trueelse:mfObj = AboutFrame(None)show_window = Truedef OnTimer(self, event):thread_obj = threading.Thread(target=self.OnTimer1, args=(event, ))thread_obj.start()def OnTimer1(self, event):passdef __del__( self ):passclass TreeFrame ( wx.Frame):sub_title = '展示树'my_frame = 'tree'def __init__( self, parent ):global percent,labelSize,textSize,buttonSize,lineHeight,username,abouttext,show_window,myFrames,myFramewx.Frame.__init__ ( self, parent, id = wx.ID_ANY, style = wx.DEFAULT_FRAME_STYLE )labelFont = wx.Font(int(18*percent), wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)labelColor = wx.Colour( 139, 69, 19 )#设置窗口位置,大小screen_width = GetSystemMetrics(0)screen_height = GetSystemMetrics(1)window_width = int(screen_width*percent)window_height = int(screen_height*percent)self.SetSize((window_width, window_height))position_x = (screen_width - window_width) // 2position_y = (screen_height - window_height) // 2self.SetPosition(wx.Point(position_x, position_y))labelSize = (int(310*percent), int(25*percent))positionx_label1 = int(5*percent)positiony_label1 = int(5*percent)positionx_label2 = window_width - labelSize[0]positiony_label2 = int(5*percent)self.usernameLabel = wx.StaticText(self, label='', size=labelSize)self.usernameLabel.SetPosition(wx.Point(positionx_label1, positiony_label1))self.usernameLabel.SetFont(labelFont)self.usernameLabel.SetForegroundColour(labelColor)if username == '':username = '未知用户'self.usernameLabel = wx.StaticText(self, label='登录用户:'+username, size=labelSize)self.usernameLabel.SetPosition(wx.Point(positionx_label2, positiony_label2))self.usernameLabel.SetFont(labelFont)self.usernameLabel.SetForegroundColour(labelColor)if not username == '未知用户':self.usernameLabel.Bind( wx.EVT_LEFT_DOWN, self.logout )textSize1 = (int(1880*percent), int(945*percent))positionx_label3 = int(8*percent)positiony_label3 = int(30*percent)self.tree = wx.TreeCtrl(self, size=textSize1)self.tree.SetPosition(wx.Point(positionx_label3, positiony_label3))self.root = self.tree.AddRoot("食物")self.zhushi = self.tree.AppendItem(self.root, "主食")self.shucai = self.tree.AppendItem(self.root, "蔬菜")self.shuiguo = self.tree.AppendItem(self.root, "水果")self.mifan = self.tree.AppendItem(self.zhushi, "米饭")self.miantiao = self.tree.AppendItem(self.zhushi, "面条")self.shuijiao = self.tree.AppendItem(self.zhushi, "水饺")self.chaocai = self.tree.AppendItem(self.zhushi, "炒菜")self.liangbancai = self.tree.AppendItem(self.zhushi, "凉拌菜")self.tree.AppendItem(self.shucai, "土豆")self.tree.AppendItem(self.shucai, "青椒")self.tree.AppendItem(self.shucai, "西红柿")self.tree.AppendItem(self.shucai, "茄子")self.tree.AppendItem(self.shucai, "青菜")self.tree.AppendItem(self.shucai, "芹菜")self.tree.AppendItem(self.shucai, "辣椒")self.tree.AppendItem(self.shucai, "豆角")self.tree.AppendItem(self.shuiguo, "西瓜")self.tree.AppendItem(self.shuiguo, "葡萄")self.tree.AppendItem(self.shuiguo, "桃子")self.tree.AppendItem(self.shuiguo, "苹果")self.tree.AppendItem(self.shuiguo, "橘子")self.tree.AppendItem(self.shuiguo, "哈密瓜")self.tree.AppendItem(self.miantiao, "炸酱面")self.tree.AppendItem(self.miantiao, "板面")self.tree.AppendItem(self.miantiao, "烩面")self.tree.AppendItem(self.miantiao, "刀削面")self.tree.AppendItem(self.miantiao, "扯面")self.tree.AppendItem(self.miantiao, "云吞面")self.tree.Expand(self.root)self.tree.Expand(self.zhushi)self.tree.Expand(self.miantiao)#添加菜单self.appendmenus()self.SetWindowStyle(wx.STAY_ON_TOP | wx.CAPTION | wx.SYSTEM_MENU)self.SetTitle(APP_TITLE+'-'+self.sub_title)self.SetIcon(wx.Icon(APP_ICON))self.SetBackgroundColour( wx.Colour( 245, 222, 179 ) )self.Raise()self.Show(True)show_window = TruemyFrame = self.my_frameif not myFrame in myFrames:myFrames[myFrame] = self#绑定事件self.timer = wx.Timer(self)self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)self.timer.Start(3000)def appendmenus(self):menu_bar = wx.MenuBar()gongneng_menu = wx.Menu()guanyu_menu = wx.Menu()index_item = gongneng_menu.Append(-1, "&首页", "返回首页")user_item1 = gongneng_menu.Append(-1, "&用户列表", "查看用户信息")tree_item1 = gongneng_menu.Append(-1, "&展示树", "查看树形结构")about_item = guanyu_menu.Append(-1, "&关于我们", "关于我们")self.Bind(wx.EVT_MENU, self.toindex, index_item)self.Bind(wx.EVT_MENU, self.touserlist, user_item1)self.Bind(wx.EVT_MENU, self.totree, tree_item1)self.Bind(wx.EVT_MENU, self.toabout, about_item)menu_bar.Append(gongneng_menu, "&功能")menu_bar.Append(guanyu_menu, "&关于")self.SetMenuBar(menu_bar)def logout(self, event):global username, passworddlg = wx.MessageDialog(None, '确认退出吗?', '用户确认', wx.YES_NO)result = dlg.ShowModal()if result == wx.ID_YES:username = ''password = ''self.tologin(event)else:passdlg.Destroy()return Truedef tologin(self, event):global myFrames,show_window,myFrameself.Hide()myFrame = 'login'if myFrame in myFrames:mfObj = myFrames[myFrame]mfObj.Show(True)show_window = Trueelse:mfObj = MainFrame(None)show_window = Truedef toindex(self, event):global myFrames,show_window,myFrameself.Hide()myFrame = 'main'if myFrame in myFrames:mfObj = myFrames[myFrame]mfObj.Show(True)show_window = Trueelse:mfObj = MainFrame(None)show_window = Truedef touserlist(self, event):global myFrames,show_window,myFrameself.Hide()myFrame = 'user'if myFrame in myFrames:mfObj = myFrames[myFrame]mfObj.Show(True)show_window = Trueelse:mfObj = UserFrame(None)show_window = Truedef totree(self, event):global myFrames,show_window,myFrameself.Hide()myFrame = 'tree'if myFrame in myFrames:mfObj = myFrames[myFrame]mfObj.Show(True)show_window = Trueelse:mfObj = TreeFrame(None)show_window = Truedef toabout(self, event):global myFrames,show_window,myFrameself.Hide()myFrame = 'about'if myFrame in myFrames:mfObj = myFrames[myFrame]mfObj.Show(True)show_window = Trueelse:mfObj = AboutFrame(None)show_window = Truedef OnTimer(self, event):thread_obj = threading.Thread(target=self.OnTimer1, args=(event, ))thread_obj.start()def OnTimer1(self, event):passdef __del__( self ):passif __name__ == "__main__":app = wx.App(False)login = LoginFrame(None)app.MainLoop()

  

截图:

 

 

 

 

 

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/779782.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

来了它来了! 中小企业“轻量化低成本”数字化转型解决方案

数字化转型是中小企业的必答题,但是初始需要投入真金白银,存在回报期长,不确定性大的问题,成本受限成为一大绊脚石。此外缺资金、缺人才、缺技术也是不可回避的挑战。找集成商无疑是一个必然的路径,但是集成商干起中小企业项目面临钱少、活多、压力大的现实问题,陷入不接…

keycloak~关于社区登录的过程说明

keycloak将第三方登录(社区登录)进行了封装,大体主要会经历以下三个过程:打开社区认证页面,输入账号密码或者扫码,完成社区上的认证 由社区进行302重定向,回到keycloak页面 keycloak与社区完成一次oauth2授权码认证,通过社区返回的code来获取token,再通过token来获取社…

免费项目管理软件:提高效率的顶级选择

国内外主流的10款免费项目管理工具对比:PingCode、Worktile、Jira 、Wrike 、ClickUp、Trello、Asana、飞书、Tapd、Teambition。在选择项目管理软件时,许多团队面临的最大挑战之一是成本。尤其是对于初创公司或小型企业来说,高昂的软件订阅费可能是一个沉重的负担。然而,市…

表达式(二)

后缀表达式由于其特殊性只需要操作数栈,不需要运算符栈,每当出现运算符就说明是对前面两个操作数进行操作 #include<bits/stdc++.h> using namespace std; char tok[30][20]; int tok_max; int pos=1;int main(){tok_max=0;int num1=0;for(;;){int c=getchar();if(c==@…

基于深度学习网络的人员行为视频检测系统matlab仿真,带GUI界面

1.算法仿真效果 matlab2022a仿真结果如下(完整代码运行后无水印): 2.算法涉及理论知识概要基于GoogLeNet深度学习网络的人员行为视频检测系统是一个高度复杂的计算机视觉应用,它利用深度神经网络的强大功能来识别和分类视频中的人员行为。GoogLeNet,也称为Inception网络,…

Forrester Wave™报告:天翼云三项产品能力获评最高分!

8月5日,国际权威研究机构Forrester发布了《Forrester Wave™: 中国公有云平台厂商评测,2024Q3》报告。中国电信天翼云凭借前瞻性的发展战略和领先的产品能力,跻身行业头部玩家阵营。同时,中国电信天翼云在数据治理服务、网络和内容交付服务、先进通讯和区块链服务三项产品能…

从理念到实践,解构HBlock降本增效黑科技!

天翼云存储资源盘活系统HBlock 2024年线上技术分享会来啦!“新存储 更轻量” 天翼云存储资源盘活系统HBlock 2024年线上技术分享会来啦! 在2023年HBlock分享会之后 不少小伙伴积极参与了1PB免费尝鲜活动 好评如潮的同时也对HBlock有了更多期待! 那么 2024年轻量存储技术有哪…

21.python函数(return)

return 一、return语句 1、return是指定一个返回值 2、在python中创建一个函数 ,可以用return语句指定返回的的值,这个返回值可以是任意的类型 3、return语句在同一个函数中可以出现多次,但是只有有一个得到执行,就会直接结束函数的执行。return后面的语句不执行了 4、retu…

C++ - 二级指针动态内存申请与释放

C语言描述: #include "stdio.h" #include "stdlib.h" #include "assert.h"void InitArray(int** Array, int row, int cols) {for (int i = 0; i < row; i++){for (int j = 0; j < cols; j++){Array[i][j] = i + j;}} } void PrintfArray…

一招致胜!天翼云对象存储攻克数据存、管、用难题!

天翼云对象存储(CT-ZOS,Zettabyte Object Storage)是一款海量、弹性、高可靠、高性价比的存储产品,也是专门针对云计算、大数据和非结构化数据的海量存储形态,通过S3协议和标准的服务接口,提供图片、音视频、文本等非结构化数据的云存储服务,助力企业高效应对数据存储挑…

一文搞懂C/C++常用编译器

1. C++ 编译器介绍1.1. MSVC1.1.1. Visual C++与Visual Studio的版本对应关系 1.1.2. 工具链的主要工具1.2. GCC1.2.1. GCC的主要优点 1.2.2. GCC的常用工具 1.2.3. MinGW1.3. Clang/LLVM1.3.1. Clang介绍 1.3.2. Clang与LLVM的关系 1.3.3. Clang/LLVM与GCC2. C++ 编译器的安装…