一.使用坐标的布局。
import wx
wildcard = "Python source (*.py; *.pyc)|*.py;*.pyc|" \
"All files (*.*)|*.*"
class MyFrame(wx.Frame):
def __init__(self,parent,ID,title):
wx.Frame.__init__(self,parent,ID,title,wx.DefaultPosition,wx.Size(250,50))
panel = wx.Panel(self,-1)
btn1 = wx.Button(panel,1,'Close',(0,0))
btn2 = wx.Button(panel,2,'OpenFile',(80,0))
btn1.Bind(wx.EVT_BUTTON,self.btn1)
btn2.Bind(wx.EVT_BUTTON,self.btn2)
def btn1(self,event):
self.Close()
def btn2(self,event):
dlg = wx.FileDialog(self,message="Choose a file",defaultFile="",wildcard=wildcard,style=wx.OPEN|wx.MULTIPLE|wx.CHANGE_DIR)
if dlg.ShowModal()==wx.ID_OK:
paths = dlg.GetPaths()
print "you chose the following file(s)."
for path in paths:
print path
dlg.Close()
if __name__=="__main__":
app = wx.PySimpleApp()
frame = MyFrame(None,-1,'Frame')
frame.Show()
frame.Centre()
app.MainLoop()
其中使用了wx.FileDialog用于打开文件。
二.使用布局管理器。