wxpython实现界面跳转
wxPython实现Frame之间的跳转/更新的一种方法
wxPython是Python中重要的GUI框架,下面通过自己的方法实现模拟类似PC版微信登录,并跳转到主界面(朋友圈)的流程。
(一)项目目录

【说明】
icon : 保存项目使用的图片资源
wx_main.py : 项目入口文件,运行此文件可以看见效果。
loginFrame.py:登录的界面的Frame定义绘制文件
contentFrame.py:登录成功之后的界面Frame定义绘制文件
guiManager.py:界面创建和管理
utils.py:工具类,其中定义了一个获取icon文件夹中文件全路径的工具函数
xDialog.py:定义了有两项输入项的Dialog的样式
(二)项目流程图

【说明】
wxPython的应用入口是在wx.App()实现的,在OnInit()函数中创建要显示的Frame对象,在wx.App子类中实现界面刷新的函数update(),并将其传递给新创建的Frame对象,在Frame需要触发Frame更新的时候,通过这个回调函数update()来通知wx.App()进行Frame的更新。
(三)效果演示
略
(四)项目代码
(4-1)wx_main.py
#coding=utf-8 import wx
import guiManager as FrameManager class MainAPP(wx.App): def OnInit(self):
self.manager = FrameManager.GuiManager(self.UpdateUI)
self.frame = self.manager.GetFrame(0)
self.frame.Show()
return True def UpdateUI(self, type):
self.frame.Show(False)
self.frame = self.manager.GetFrame(type)
self.frame.Show(True) def main():
app = MainAPP()
app.MainLoop() if __name__ == '__main__':
main()
(4-2)guiManager.py
#coding=utf-8
import loginFrame
import contentFrame class GuiManager():
def __init__(self, UpdateUI):
self.UpdateUI = UpdateUI
self.frameDict = {} # 用来装载已经创建的Frame对象 def GetFrame(self, type):
frame = self.frameDict.get(type) if frame is None:
frame = self.CreateFrame(type)
self.frameDict[type] = frame return frame def CreateFrame(self, type):
if type == 0:
return loginFrame.LoginFrame(parent=None, id=type, UpdateUI=self.UpdateUI)
elif type == 1:
return contentFrame.ContentFrame(parent=None, id=type, UpdateUI=self.UpdateUI)
(4-3)loginFrame.py
#coding=utf-8
import wx
# 导入wxPython中的通用Button
import wx.lib.buttons as wxButton from utils import load_image
import xDialog class LoginFrame(wx.Frame):
def __init__(self, parent=None, id=-1, UpdateUI=None):
wx.Frame.__init__(self, parent, id, title='登录界面', size=(280, 400), pos=(500, 200)) self.UpdateUI = UpdateUI
self.InitUI() # 绘制UI界面 def InitUI(self):
panel = wx.Panel(self) logo_sys = wx.Image(load_image('logo_sys.png'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
wx.StaticBitmap(panel, -1, logo_sys, pos=(90, 90), size=(100, 100)) logo_title = wx.StaticText(panel, -1, '天马行空', pos=(120, 210))
logo_title.SetForegroundColour('#0a74f7')
titleFont = wx.Font(13, wx.DEFAULT, wx.BOLD, wx.NORMAL, True)
logo_title.SetFont(titleFont) button_Login = wxButton.GenButton(panel, -1, '登录', pos=(40, 270), size=(200, 40), style=wx.BORDER_MASK)
button_Login.SetBackgroundColour('#0a74f7')
button_Login.SetForegroundColour('white')
self.Bind(wx.EVT_BUTTON, self.loginSys, button_Login) def loginSys(self, event):
dlg = LoginDialog(self.loginFunction, '#0a74f7')
dlg.Show() def loginFunction(self, account, password):
print '接收到用户的输入:', account, password
self.UpdateUI(1) #更新UI-Frame class LoginDialog(xDialog.InputDialog):
def __init__(self, func_callBack, themeColor):
xDialog.InputDialog.__init__(self, '登录系统', func_callBack, themeColor)
(4-4)contentFrame.py
#coding=utf-8
import wx class ContentFrame(wx.Frame):
def __init__(self, parent=None, id=-1, UpdateUI=None):
wx.Frame.__init__(self, parent, -1, title='天马行空的朋友圈', size=(400, 400), pos=(500, 200)) self.UpdateUI = UpdateUI
self.InitUI() #绘制UI def InitUI(self): panel = wx.Panel(self)
wx.StaticText(panel, -1, u'欢迎您的到来!', pos=(30, 30))
(4-5)xDialog.py
#coding=utf-8 import wx class InputDialog(wx.Dialog):
def __init__(self, title, func_callBack, themeColor):
wx.Dialog.__init__(self, None, -1, title, size=(300, 200))
self.func_callBack = func_callBack
self.themeColor = themeColor self.InitUI() #绘制Dialog的界面 def InitUI(self):
panel = wx.Panel(self) font = wx.Font(14, wx.DEFAULT, wx.BOLD, wx.NORMAL, True) accountLabel = wx.StaticText(panel, -1, '账号', pos=(20, 25))
accountLabel.SetForegroundColour(self.themeColor)
accountLabel.SetFont(font) self.accountInput = wx.TextCtrl(panel, -1, u'', pos=(80, 25), size=(180, -1))
self.accountInput.SetForegroundColour('gray')
self.accountInput.SetFont(font) passwordLabel = wx.StaticText(panel, -1, '密码', pos=(20, 70))
passwordLabel.SetFont(font)
passwordLabel.SetForegroundColour(self.themeColor) self.passwordInput = wx.TextCtrl(panel, -1, u'', pos=(80, 70), size=(180, -1), style=wx.TE_PASSWORD)
self.passwordInput.SetForegroundColour(self.themeColor)
self.passwordInput.SetFont(font) sureButton = wx.Button(panel, -1, u'登录', pos=(20, 130), size=(120, 40))
sureButton.SetForegroundColour('white')
sureButton.SetBackgroundColour(self.themeColor)
# 为【确定Button】绑定事件
self.Bind(wx.EVT_BUTTON, self.sureEvent, sureButton) cancleButton = wx.Button(panel, -1, u'取消', pos=(160, 130), size=(120, 40))
cancleButton.SetBackgroundColour('black')
cancleButton.SetForegroundColour('#ffffff')
# 为【取消Button】绑定事件
self.Bind(wx.EVT_BUTTON, self.cancleEvent, cancleButton) def sureEvent(self, event):
account = self.accountInput.GetValue()
password = self.passwordInput.GetValue()
# 通过回调函数传递数值
self.func_callBack(account, password)
self.Destroy() #销毁隐藏Dialog def cancleEvent(self, event):
self.Destroy() #销毁隐藏Dialog
(4-6)utils.py
#coding=utf-8
import os.path main_dir = os.path.split(os.path.abspath(__file__))[0] # 返回icon中文件的系统文件路径
def load_image(file):
filePath = os.path.join(main_dir, 'icon', file)
return filePath
荡的,不是本人作品
wxpython实现界面跳转的更多相关文章
- Android 手机卫士--设置界面&功能列表界面跳转逻辑处理
在<Android 手机卫士--md5加密过程>中已经实现了加密类,这里接着实现手机防盗功能 本文地址:http://www.cnblogs.com/wuyudong/p/5941959. ...
- iOS界面跳转的一些优化方案
原文地址: http://blog.startry.com/2016/02/14/Think-Of-UIViewController-Switch/ iOS界面跳转的一些优化方案 App应用程序开发, ...
- Android activity界面跳转动画
实现activity界面跳转动画 1.在startActivity方法之后加入: overridePendingTransition(R.anim.pull_in_right, R.anim.pull ...
- 如何优雅的实现界面跳转 之 统跳协议 - DarwinNativeRouter
PS 感谢大家的关注,由于我本想开源4个库,除了router, 另外三个分别是native dispatcher, web dispatcher 和 react dispatcher , 所以rout ...
- ios中的界面跳转方式
ios中,两种界面跳转方式 1.NavgationController本身可以作为普通ViewController的容器,它有装Controller的栈,所以可以push和pop它们,实现你所说的跳转 ...
- PyQt5实现界面跳转
网上关于PyQt5的教程很少,特别是界面跳转这一块儿,自己研究了半天,下来和大家分享一下 一.首先是主界面 1 # -*- coding: utf-8 -*- # Form implementatio ...
- Android原生和H5交互;Android和H5混合开发;WebView点击H5界面跳转到Android原生界面。
当时业务的需求是这样的,H5有一个活动商品列表的界面,IOS和Android共用这一个界面,点击商品可以跳转到Android原生的商品详情界面并传递商品ID: 大概就是点击H5界面跳转到Androi ...
- ios的两种界面跳转方式
1.在界面的跳转有两种方法,一种方法是先删除原来的界面,然后在插入新的界面,使用这种方式无法实现界面跳转时的动画效果. if(self.rootViewController.view.supervie ...
- Android之Activity界面跳转--生命周期方法调用顺序
这本是一个很基础的问题,很惭愧,很久没研究这一块了,已经忘得差不多了.前段时间面试,有面试官问过这个问题.虽然觉得没必要记,要用的时候写个Demo,打个Log就清楚了.但是今天顺手写了个Demo,也就 ...
随机推荐
- Java枚举类"全方位"
作为一种长度固定,数据未定的一种存储数据集的数据类型,枚举类有如下方法可供参考. 普通类型的枚举类的创建 protected enum ColorEnum{ red,orange,yellow,gre ...
- 使用spine骨骼动画制作的libgdx游戏
(官网:www.libgdx.cn) Super Spineboy是一个使用Spine和libgdx开发的跨平台游戏(Windows,Mac,Linux),Spine是一个2D游戏动画工具.Super ...
- MySQL学习笔记_5_SQL语言的设计与编写(上)
SQL语言的设计与编写(上) 一.SQL语句分类 数据定义语言(DDL): 用于定义和管理数据对象,包括数据库.数据表.视图.索引等.例如:CREATE.DROP.ALTER等语句. 数据操作语言(D ...
- mpi中程序在集群中的分发
我们在开发mpi程序时,由于其是分布式程序,我们在单个节点上完成编码后,需要将代码拷贝到整个集群进行测试.集群之间的文件拷贝可以通过scp命令完成.但是scp命令是针对两个节点之间文件互传设计,为了将 ...
- Android安全机制浅谈-android学习之旅(80)
由于Android安全机制存在,使得漏洞利用有一些困难. ASLR:即地址空间格局随机化.ASLR使得加载程序时不使用固定的基址加载,防止攻击者直接定位攻击代码位置,从而阻止溢出攻击 NX:(No e ...
- 开源框架VTMagic的使用介绍
VTMagic 有很多开发者曾尝试模仿写出类似网易.腾讯等应用的菜单分页组件,但遍观其设计,大多都比较粗糙,不利于后续维护和扩展.琢磨良久,最终决定开源这个耗时近两年打磨而成的框架,以便大家可以快速实 ...
- node.js 连接数据库
用Nodejs连接MySQL 用Nodejs连接MySQL 从零开始nodejs系列文章 ,将介绍如何利Javascript做为服务端脚本,通过Nodejs框架web开发.Nodejs框架是基于V8的 ...
- 【一天一道LeetCode】#11Container With Most Water
一天一道LeetCode系列 (一)题目 Given n non-negative integers a1, a2, -, an, where each represents a point at c ...
- PS 图像调整算法——阈值
PS里面这个算法,先将图像转成灰度图像,然后根据给定的阈值,大于该阈值的像素赋值为1,小于该阈值的赋值为0. if x>T, x=1; if x<T, x=0; 原图: 效果图:阈值为 1 ...
- 记——加快gradle 构建速度的经验
Gradle作为一个新的构建系统,无疑在灵活,扩展,跨平台等各方面都表现得非常优秀,然而,它也有一点备受吐槽,就是速度慢.以下为本人使用gradle过程中,几次加快gradle构建速度的经验之谈. 本 ...