wxpython教程 中谷
点击(此处)折叠或打开
#导入库
import wx
#实例化一个app
app=wx.App()
#创建一个Frame
win = wx.Frame(None,title="HelloWorld!!",size=(450,300))
"""
OpenBtn = wx.Button(win,label="Open",size=(80,25),pos=(315,0))
SaveBtn = wx.Button(win,label="Save",size=(80,25),pos=(230,0))
"""
#打开布局画板
Bkg=wx.Panel(win)
#创建一个水平布局箱子
Hbox=wx.BoxSizer(wx.HORIZONTAL)
OpenBtn = wx.Button(Bkg,label="Open")
SaveBtn = wx.Button(Bkg,label="Save")
NameTxtCtl = wx.TextCtrl(Bkg)
Hbox.Add(NameTxtCtl,proportion=1,flag=wx.EXPAND)
Hbox.Add(OpenBtn,proportion=0,flag=wx.LEFT,border=5)
Hbox.Add(SaveBtn,proportion=0,flag=wx.LEFT,border=5)
ContentsTxtCtl=wx.TextCtrl(Bkg)
#创建一个垂直布局箱子
Vbox=wx.BoxSizer(wx.VERTICAL )
Vbox.Add(Hbox,proportion=0,flag=wx.EXPAND|wx.ALL,border=5)
Vbox.Add(ContentsTxtCtl,proportion=1,flag=wx.EXPAND|wx.LEFT|wx.RIGHT|wx.BOTTOM,border=5)
Bkg.SetSizer(Vbox)
#显示
win.Show()
#主循环
app.MainLoop()
运行结果:
转自:http://blog.chinaunix.net/uid-29630160-id-4705703.html