博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用 wxFormBuiler 做wxPython UI
阅读量:5875 次
发布时间:2019-06-19

本文共 5457 字,大约阅读时间需要 18 分钟。

 

如上图,使用wxFormBulider 实现的简单的图形界面,又是拖控件啊,然后 直接查看python代码, 拿出来 几乎不用修改就可以直接运行。贴一段用wxFormBulider 实现的ui

# -*- coding: utf-8 -*- ############################################################################# Python code generated with wxFormBuilder (version Oct  8 2012)## http://www.wxformbuilder.org/#### PLEASE DO "NOT" EDIT THIS FILE!###########################################################################import wximport wx.xrcimport sysimport os############################################################################# Class MyFrame2###########################################################################class MyFrame2 ( wx.Frame ):		def __init__( self ):		wx.Frame.__init__ ( self, None, id = wx.ID_ANY, title = u"wo cao ", pos = wx.DefaultPosition, size = wx.Size( 502,644 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )				self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )				bSizer3 = wx.BoxSizer( wx.VERTICAL )				self.m_panel4 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )		self.m_panel4.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_ACTIVEBORDER ) )				bSizer4 = wx.BoxSizer( wx.VERTICAL )				self.m_static_fileName = wx.StaticText( self.m_panel4, wx.ID_ANY, u"未打开文件", wx.DefaultPosition, wx.DefaultSize, 0 )		self.m_static_fileName.Wrap( -1 )		bSizer4.Add( self.m_static_fileName, 0, wx.ALL|wx.EXPAND, 5 )				self.m_staticline1 = wx.StaticLine( self.m_panel4, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL )		bSizer4.Add( self.m_staticline1, 0, wx.EXPAND |wx.ALL, 5 )				self.m_textCtrl1 = wx.TextCtrl( self.m_panel4, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.TE_MULTILINE )		self.m_textCtrl1.SetBackgroundColour( wx.Colour( 0, 0, 0 ) )                self.m_textCtrl1.SetForegroundColour( wx.Colour( 240, 240, 240 ) )		bSizer4.Add( self.m_textCtrl1, 1, wx.ALL|wx.EXPAND, 5 )						self.m_panel4.SetSizer( bSizer4 )		self.m_panel4.Layout()		bSizer4.Fit( self.m_panel4 )		bSizer3.Add( self.m_panel4, 1, wx.EXPAND |wx.ALL, 5 )						self.SetSizer( bSizer3 )		self.Layout()		self.m_menubar3 = wx.MenuBar( 0 )		self.m_menu1 = wx.Menu()		self.m_openFile = wx.MenuItem( self.m_menu1, wx.ID_ANY, u"打开"+ u"\t" + u"------  ctrl + f", wx.EmptyString, wx.ITEM_NORMAL )		self.m_menu1.AppendItem( self.m_openFile )				self.m_save = wx.MenuItem( self.m_menu1, wx.ID_ANY, u"保存"+ u"\t" + u"------  ctrl + s", wx.EmptyString, wx.ITEM_NORMAL )		self.m_menu1.AppendItem( self.m_save )				self.m_menu1.AppendSeparator()				self.m_close = wx.MenuItem( self.m_menu1, wx.ID_ANY, u"关闭", wx.EmptyString, wx.ITEM_NORMAL )		self.m_menu1.AppendItem( self.m_close )				self.m_ext = wx.MenuItem( self.m_menu1, wx.ID_ANY, u"退出"+ u"\t" + u"------  alt + F4", wx.EmptyString, wx.ITEM_NORMAL )		self.m_menu1.AppendItem( self.m_ext )				self.m_menubar3.Append( self.m_menu1, u"文件" ) 				self.m_menu2 = wx.Menu()		self.m_run = wx.MenuItem( self.m_menu2, wx.ID_ANY, u"运行"+ u"\t" + u"------  F5", wx.EmptyString, wx.ITEM_NORMAL )		self.m_menu2.AppendItem( self.m_run )				self.m_debug = wx.MenuItem( self.m_menu2, wx.ID_ANY, u"调试"+ u"\t" + u"------  F3", wx.EmptyString, wx.ITEM_NORMAL )		self.m_menu2.AppendItem( self.m_debug )				self.m_menuItem8 = wx.MenuItem( self.m_menu2, wx.ID_ANY, u"保留位", wx.EmptyString, wx.ITEM_NORMAL )		self.m_menu2.AppendItem( self.m_menuItem8 )				self.m_menubar3.Append( self.m_menu2, u"工具" ) 				self.SetMenuBar( self.m_menubar3 )		                  self.m_statusBar = self.CreateStatusBar( 1, wx.ST_SIZEGRIP, wx.ID_ANY )				self.Centre( wx.BOTH )				# Connect Events 		self.Bind( wx.EVT_MENU, self.OpenFile, id = self.m_openFile.GetId() )		self.Bind( wx.EVT_MENU, self.FormDestory, id = self.m_ext.GetId() )		self.Bind( wx.EVT_MENU, self.SaveFile, id = self.m_save.GetId() )		self.Bind( wx.EVT_MENU, self.CloseForm, id = self.m_close.GetId() )		def __del__( self ):		pass			# Virtual event handlers, overide them in your derived class	def FormDestory( self, event ):		self.Destroy()  	def OpenFile( self, event ):		self.dirname = ''		dlg = wx.FileDialog(self,"chose a file",self.dirname,"","*.*",wx.OPEN)		if dlg.ShowModal() == wx.ID_OK:                  self.filename = dlg.GetFilename()                  self.dirname = dlg.GetDirectory()                  filePath = self.dirname + self.filename                  self.m_static_fileName.SetLabel(filePath)                  #print self.dirname                  f = open(os.path.join(self.dirname,self.filename),'r')                  self.m_textCtrl1.SetValue(f.read())                  f.close()                dlg.Destroy()                                	def SaveFile( self, event ):                try:                    f = open(os.path.join(self.dirname,self.filename),'w')                except AttributeError:                    print '文件不存在'                    sys.exit(0)                               content = self.m_textCtrl1.GetValue()                try:                    f.write(content)                except UnboundLocalError:                    print '文件不存在'                    sys.exit(0)                finally:                    f.close()	def CloseForm( self, event ):                self.m_static_fileName.SetLabel(u'未打开文件')                self.m_textCtrl1.SetValue(u'')                    app = wx.PySimpleApp()frame = MyFrame2()frame.Show()app.MainLoop()

 另外 该工具还支持 c++ / php, 是的你没看错,是php。不过我美使用过。。。

转载于:https://www.cnblogs.com/lunsa/archive/2013/03/14/2959511.html

你可能感兴趣的文章
那些年追过的......写过的技术博客
查看>>
小米手机解锁bootload教程及常见问题
查看>>
Python内置函数property()使用实例
查看>>
Spring MVC NoClassDefFoundError 问题的解决方法。
查看>>
CentOS 6.9配置网卡IP/网关/DNS命令详细介绍及一些常用网络配置命令(转)
查看>>
python基础教程_学习笔记19:标准库:一些最爱——集合、堆和双端队列
查看>>
C# 解决窗体闪烁
查看>>
CSS魔法堂:Transition就这么好玩
查看>>
【OpenStack】network相关知识学习
查看>>
centos 7下独立的python 2.7环境安装
查看>>
[日常] 算法-单链表的创建
查看>>
前端工程化系列[01]-Bower包管理工具的使用
查看>>
使用 maven 自动将源码打包并发布
查看>>
Spark:求出分组内的TopN
查看>>
Python爬取豆瓣《复仇者联盟3》评论并生成乖萌的格鲁特
查看>>
关于跨DB增量(增、改)同步两张表的数据小技巧
查看>>
飞秋无法显示局域网好友
查看>>
学员会诊之03:你那惨不忍睹的三层架构
查看>>
vue-04-组件
查看>>
Golang协程与通道整理
查看>>