wxpython初学者(三)
2015-09-07 21:18
399 查看
这几天一直趴在wxpython中,发现还是很有意思的,不过有些对于目前的我感觉还是太陌生了,下午幸亏回眸那一下顿悟了,才没有去上网休息休息,坚持下去总会看到自己想要的,我应该还是多练习吧,我一直用sublime编写,这个编辑器还是不错的,有些是我乱加的,本来想截图的的,可是还要装什么scrot截图工具太麻烦了。对于下面的代码主要是gridbagsizer那里的,
<span style="font-size:18px;">#!/usr/bin python
#coding:utf-8
#wx.gridbagsizer
import wx
class Example(wx.Frame):
def __init__(self,parent,title):
super(Example,self).__init__(parent,title=title,size=(320,200))
self.InitUI()
self.Centre()
self.Show()
def InitUI(self):
panel = wx.Panel(self)
sizer = wx.GridBagSizer(4,4)
text = wx.StaticText(panel,label= "Rename to")
sizer.Add(text,pos=(0,0),flag=wx.TOP | wx.LEFT | wx.BOTTOM ,border=5)
tc = wx.TextCtrl(panel)
sizer.Add(tc,pos=(0,1),span=(1,5),flag=wx.EXPAND | wx.LEFT | wx.RIGHT,border= 5)
#sizer.Add(tc,pos=(1,0),span=(1,5),flag=wx.EXPAND | wx.LEFT | wx.RIGHT,border= 5)
buttonOK = wx.Button(panel,label ="OK",size=(90,28))
self.Bind(wx.EVT_BUTTON,self.OnCloseMe1,buttonOK)
buttonClose = wx.Button(panel,label="Close",size =(90,28))
self.Bind(wx.EVT_BUTTON,self.OnCloseMe2,buttonClose)
sizer.Add(buttonOK,pos= (3,3))
sizer.Add(buttonClose,pos=(3,4),flag = wx.RIGHT | wx.BOTTOM ,border = 5)
sizer.AddGrowableRow(2)
sizer.AddGrowableCol(1)
panel.SetSizerAndFit(sizer)
def OnCloseMe1(self, event):
dlg = wx.MessageDialog(None, u"消息对话框测试", u"标题信息", wx.YES_NO | wx.ICON_QUESTION)
if dlg.ShowModal() == wx.ID_YES:
self.Close(True)
dlg.Destroy()
def OnCloseMe2(self,event):
self.Close()
if __name__ == '__main__':
app = wx.App()
Example(None,title="GridBagSizer")
app.MainLoop()</span>
<span style="font-size:18px;">#!/usr/bin python
#coding:utf-8
#wxgridbagsizer
import wx
class Example(wx.Frame):
def __init__(self,parent,title):
super(Example,self).__init__(parent,title=title,size = (300,250))
self.InitUI()
self.Centre()
self.Show()
def InitUI(self):
sizer = wx.GridBagSizer(10,10)
sizer.Add(wx.Button(self,-1,"Button1"),(0,0),wx.DefaultSpan,wx.ALL,35)
sizer.Add(wx.Button(self,-1,"Button2"),(1,1),(1,7),wx.EXPAND)
sizer.Add(wx.Button(self,-1,"Button3"),(6,6),(3,3),wx.EXPAND)
sizer.Add(wx.Button(self,-1,"Button4"),(3,0),(1,1),wx.ALIGN_CENTER)
sizer.Add(wx.Button(self,-1,"Button5"),(4,0),(1,1),wx.ALIGN_LEFT)
sizer.Add(wx.Button(self,-1,"Button6"),(5,0),(1,1),wx.ALIGN_RIGHT)
sizer.AddGrowableRow(6)
sizer.AddGrowableCol(6)
self.SetSizerAndFit(sizer)
def main():
app = wx.App()
Example(None,title="GridBagSizer")
app.MainLoop()
if __name__ == '__main__':
main()
</span>
下面的这个gridsizer仅仅只是做了向一个计算器的样子,并没有写事件驱动和后面的程序,等学的差不多在说吧
<span style="font-size:18px;">#!/usr/bin python
#coding:utf-8
#wx.GridSizer
import wx
class Example(wx.Frame):
def __init__(self,parent,title):
super(Example,self).__init__(parent,title=title,size=(300,250))
self.InitUI()
self.Centre()
self.Show()
def InitUI(self):
menubar = wx.MenuBar()
fileMenu = wx.Menu()
menubar.Append(fileMenu,"&file")
self.SetMenuBar(menubar)
vbox = wx.BoxSizer(wx.VERTICAL)
self.display = wx.TextCtrl(self,style =wx.TE_RIGHT)
vbox.Add(self.display,flag = wx.EXPAND | wx.TOP | wx.BOTTOM,border = 5)
gs = wx.GridSizer(4,4,5,5)
gs.AddMany([(wx.Button(self,label = 'Cls'),0,wx.EXPAND),
(wx.Button(self,label = 'Bck'),0,wx.EXPAND),
(wx.StaticText(self),wx.EXPAND),
(wx.Button(self,label = 'Close'),0,wx.EXPAND),
(wx.Button(self,label = '7'),0,wx.EXPAND),
(wx.Button(self,label = '8'),0,wx.EXPAND),
(wx.Button(self,label = '9'),0,wx.EXPAND),
(wx.Button(self,label = '/'),0,wx.EXPAND),
(wx.Button(self,label = '4'),0,wx.EXPAND),
(wx.Button(self,label = '5'),0,wx.EXPAND),
(wx.Button(self,label = '6'),0,wx.EXPAND),
(wx.Button(self,label = '*'),0,wx.EXPAND),
(wx.Button(self,label = '1'),0,wx.EXPAND),
(wx.Button(self,label = '2'),0,wx.EXPAND),
(wx.Button(self,label = '3'),0,wx.EXPAND),
(wx.Button(self,label = '-'),0,wx.EXPAND),
(wx.Button(self,label = '0'),0,wx.EXPAND),
(wx.Button(self,label = '.'),0,wx.EXPAND),
(wx.Button(self,label = '='),0,wx.EXPAND),
(wx.Button(self,label = '+'),0,wx.EXPAND)])
vbox.Add(gs,proportion=1,flag=wx.EXPAND)
self.SetSizer(vbox)
if __name__ == '__main__':
app = wx.App()
Example(None,title="caculator")
app.MainLoop()</span>
<span style="font-size:18px;">#!/usr/bin python
#coding:utf-8
#wx.gridbagsizer
import wx
class Example(wx.Frame):
def __init__(self,parent,title):
super(Example,self).__init__(parent,title=title,size=(320,200))
self.InitUI()
self.Centre()
self.Show()
def InitUI(self):
panel = wx.Panel(self)
sizer = wx.GridBagSizer(4,4)
text = wx.StaticText(panel,label= "Rename to")
sizer.Add(text,pos=(0,0),flag=wx.TOP | wx.LEFT | wx.BOTTOM ,border=5)
tc = wx.TextCtrl(panel)
sizer.Add(tc,pos=(0,1),span=(1,5),flag=wx.EXPAND | wx.LEFT | wx.RIGHT,border= 5)
#sizer.Add(tc,pos=(1,0),span=(1,5),flag=wx.EXPAND | wx.LEFT | wx.RIGHT,border= 5)
buttonOK = wx.Button(panel,label ="OK",size=(90,28))
self.Bind(wx.EVT_BUTTON,self.OnCloseMe1,buttonOK)
buttonClose = wx.Button(panel,label="Close",size =(90,28))
self.Bind(wx.EVT_BUTTON,self.OnCloseMe2,buttonClose)
sizer.Add(buttonOK,pos= (3,3))
sizer.Add(buttonClose,pos=(3,4),flag = wx.RIGHT | wx.BOTTOM ,border = 5)
sizer.AddGrowableRow(2)
sizer.AddGrowableCol(1)
panel.SetSizerAndFit(sizer)
def OnCloseMe1(self, event):
dlg = wx.MessageDialog(None, u"消息对话框测试", u"标题信息", wx.YES_NO | wx.ICON_QUESTION)
if dlg.ShowModal() == wx.ID_YES:
self.Close(True)
dlg.Destroy()
def OnCloseMe2(self,event):
self.Close()
if __name__ == '__main__':
app = wx.App()
Example(None,title="GridBagSizer")
app.MainLoop()</span>
<span style="font-size:18px;">#!/usr/bin python
#coding:utf-8
#wxgridbagsizer
import wx
class Example(wx.Frame):
def __init__(self,parent,title):
super(Example,self).__init__(parent,title=title,size = (300,250))
self.InitUI()
self.Centre()
self.Show()
def InitUI(self):
sizer = wx.GridBagSizer(10,10)
sizer.Add(wx.Button(self,-1,"Button1"),(0,0),wx.DefaultSpan,wx.ALL,35)
sizer.Add(wx.Button(self,-1,"Button2"),(1,1),(1,7),wx.EXPAND)
sizer.Add(wx.Button(self,-1,"Button3"),(6,6),(3,3),wx.EXPAND)
sizer.Add(wx.Button(self,-1,"Button4"),(3,0),(1,1),wx.ALIGN_CENTER)
sizer.Add(wx.Button(self,-1,"Button5"),(4,0),(1,1),wx.ALIGN_LEFT)
sizer.Add(wx.Button(self,-1,"Button6"),(5,0),(1,1),wx.ALIGN_RIGHT)
sizer.AddGrowableRow(6)
sizer.AddGrowableCol(6)
self.SetSizerAndFit(sizer)
def main():
app = wx.App()
Example(None,title="GridBagSizer")
app.MainLoop()
if __name__ == '__main__':
main()
</span>
下面的这个gridsizer仅仅只是做了向一个计算器的样子,并没有写事件驱动和后面的程序,等学的差不多在说吧
<span style="font-size:18px;">#!/usr/bin python
#coding:utf-8
#wx.GridSizer
import wx
class Example(wx.Frame):
def __init__(self,parent,title):
super(Example,self).__init__(parent,title=title,size=(300,250))
self.InitUI()
self.Centre()
self.Show()
def InitUI(self):
menubar = wx.MenuBar()
fileMenu = wx.Menu()
menubar.Append(fileMenu,"&file")
self.SetMenuBar(menubar)
vbox = wx.BoxSizer(wx.VERTICAL)
self.display = wx.TextCtrl(self,style =wx.TE_RIGHT)
vbox.Add(self.display,flag = wx.EXPAND | wx.TOP | wx.BOTTOM,border = 5)
gs = wx.GridSizer(4,4,5,5)
gs.AddMany([(wx.Button(self,label = 'Cls'),0,wx.EXPAND),
(wx.Button(self,label = 'Bck'),0,wx.EXPAND),
(wx.StaticText(self),wx.EXPAND),
(wx.Button(self,label = 'Close'),0,wx.EXPAND),
(wx.Button(self,label = '7'),0,wx.EXPAND),
(wx.Button(self,label = '8'),0,wx.EXPAND),
(wx.Button(self,label = '9'),0,wx.EXPAND),
(wx.Button(self,label = '/'),0,wx.EXPAND),
(wx.Button(self,label = '4'),0,wx.EXPAND),
(wx.Button(self,label = '5'),0,wx.EXPAND),
(wx.Button(self,label = '6'),0,wx.EXPAND),
(wx.Button(self,label = '*'),0,wx.EXPAND),
(wx.Button(self,label = '1'),0,wx.EXPAND),
(wx.Button(self,label = '2'),0,wx.EXPAND),
(wx.Button(self,label = '3'),0,wx.EXPAND),
(wx.Button(self,label = '-'),0,wx.EXPAND),
(wx.Button(self,label = '0'),0,wx.EXPAND),
(wx.Button(self,label = '.'),0,wx.EXPAND),
(wx.Button(self,label = '='),0,wx.EXPAND),
(wx.Button(self,label = '+'),0,wx.EXPAND)])
vbox.Add(gs,proportion=1,flag=wx.EXPAND)
self.SetSizer(vbox)
if __name__ == '__main__':
app = wx.App()
Example(None,title="caculator")
app.MainLoop()</span>
相关文章推荐
- “Python"学习笔记(四)(函数二)
- 2 Dimension list (list中的list)game 2048 part2
- Python之面向对象初体验
- python会什么比c慢
- Python 之 Post 登陆 Dz 论坛
- mac下安装MYSQL-python
- 使SourceInsight支持Python语言的方法
- python实现并行爬虫
- python——ADSL拨号程序
- 将 Sublime 3 打造成 Python/Django IDE
- Python的函数参数传递:传值?引用?
- python中判断语句
- python_正则表达式
- python-文件替换二进制脚本
- python元字典
- [LeetCode]题解(python):004-Median of Two Sorted Arrays
- python中元组介绍
- python笔记0;extnd方法
- Mac 上配置Python开发环境 Pydev + Eclipse
- python中的高阶函数