下午去世博家园打完篮球回来。
家人都在休息,我也就趁空,再看了一会PYTHON的东东。
一行一行的按书写了窗口代码。
由于书上推荐用WXPYTHON测试,而WX最新只支持PYTHON2.7.3,那只好先用这个版本测试了。
代码:
1 import wx 2 3 def load(event): 4 file = open(filename.GetValue()) 5 contents.SetValue(file.read()) 6 file.close() 7 8 def save(event): 9 file = open(filename.GetValue(), 'w') 10 file.write(contents.GetValue()) 11 file.close() 12 13 app = wx.App() 14 win = wx.Frame(None, title="Simple Editor", size=(410,335)) 15 bkg = wx.Panel(win) 16 17 loadButton = wx.Button(bkg, label='Open') 18 loadButton.Bind(wx.EVT_BUTTON, load) 19 20 saveButton = wx.Button(bkg, label='Save') 21 saveButton.Bind(wx.EVT_BUTTON, save) 22 23 filename = wx.TextCtrl(bkg) 24 contents = wx.TextCtrl(bkg, style=wx.TE_MULTILINE | wx.HSCROLL) 25 26 hbox = wx.BoxSizer() 27 hbox.Add(filename, proportion=1, flag=wx.EXPAND) 28 hbox.Add(loadButton, proportion=0, flag=wx.LEFT, border=5) 29 hbox.Add(saveButton, proportion=0, flag=wx.LEFT, border=5) 30 31 vbox = wx.BoxSizer(wx.VERTICAL) 32 vbox.Add(hbox, proportion=0, flag=wx.EXPAND | wx.ALL, border=5) 33 vbox.Add(contents, proportion=1, 34 flag=wx.EXPAND | wx.LEFT | wx.BOTTOM | wx.RIGHT, border=5) 35 36 bkg.SetSizer(vbox) 37 win.Show() 38 39 app.MainLoop()
效果图:
时间: 2024-11-17 10:54:54