[这段时间一直在学wxpython,但一直以读代码为主,总感觉不写点,无法进步,所以就在这开一个写wxpython代码的头,以资鼓励...]
这篇其实比较简单,就是一个带有按钮的窗口,但点击这个按钮后提示一个对话框。
import wx
class SubclassDialog(wx.Dialog):
def __init__(self):
wx.Dialog.__init__(self, None, -1, 'Dialog',
pos=(200,200),size=(300, 100))
okButton = wx.Button(self, wx.ID_OK, "OK", pos=(15, 15))
okButton.SetDefault()
cancelButton = wx.Button(self, wx.ID_CANCEL, "Cancel",
pos=(115, 15))
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,-1,'Study dialog of wxpython')
panel=wx.Panel(self,-1)
button=wx.Button(panel,-1,"Open dialog!",pos=(150,70),size=(100,50),style=wx.BU_EXACTFIT)
button.Bind(wx.EVT_BUTTON,self.OnOpenDialog)
def OnOpenDialog(self,evt):
dialog = SubclassDialog()
result = dialog.ShowModal()
if result == wx.ID_OK:
print "OK"
else:
print "Cancel"
dialog.Destroy()
if __name__=='__main__':
app=wx.PySimpleApp()
frame=TestFrame()
frame.Show()
app.MainLoop()