wxPython的简单使用

+看书。

import wx

def load(event):
    file = open(filename.GetValue())
    contents.SetValue(file.read())
    file.close()
    
def save(event):
    file = open(filename.GetValue(),'w')
    file.write(contents.GetValue())
    file.close()

app = wx.App()
win = wx.Frame(None,title='Simple Editor', size=(800,600))

bkg = wx.Panel(win)
openBtn = wx.Button(bkg,label='Open')
saveBtn = wx.Button(bkg,label='Save')
filename = wx.TextCtrl(bkg)
contents = wx.TextCtrl(bkg,style=wx.TE_MULTILINE|wx.HSCROLL)

hbox = wx.BoxSizer(wx.HORIZONTAL)
hbox.Add(filename,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)

vbox = wx.BoxSizer(wx.VERTICAL)
vbox.Add(hbox,proportion=0, flag=wx.EXPAND|wx.ALL, border=5)
vbox.Add(contents,proportion=1, flag=wx.EXPAND|wx.LEFT|wx.BOTTOM|wx.RIGHT, border=5)

openBtn.Bind(wx.EVT_BUTTON, load)
saveBtn.Bind(wx.EVT_BUTTON, save)

bkg.SetSizer(vbox)
win.Show() #show要放到最后,否则不会出现你预期目的
app.MainLoop()


简单使用,就是安装wxPython遇到了困难,好像只能使用python2.6版本的和wxPython2.8-win32-unicode-2.8.12.1-py26.exe配对

你可能感兴趣的:(wxPython)