- 论坛徽章:
- 0
|
代码:
- #!/usr/bin/env python
- import wx
- class MyFrame(wx.Frame):
- def __init__(self, parent, id=-1):
- wx.Frame.__init__(self, parent, id, title='dialog')
- panel = wx.Panel(self)
- but_message = wx.Button(panel, label='Message', pos=(125,10), size=(100,50))
- but_choose = wx.Button(panel, label='Choose', pos=(125,100), size=(100,50)) #??
- self.Bind(wx.EVT_BUTTON, self.evt_message, but_message)
- self.Bind(wx.EVT_BUTTON, self.evt_choose, but_choose) #??
- self.Bind(wx.EVT_CLOSE, self.evt_close)
- pass
- def evt_message(self, event):
- dlg = wx.MessageDialog(None, 'Is this the coolest thing ever?',
- 'MessageDialog', wx.YES_NO | wx.ICON_QUESTION)
- result = dlg.ShowModal()
- print result
- dlg.Destroy()
- def evt_choose(self, event):
- choice = ['abc', 'def', 'ghi']
- dlg = wx.SingleChoiceDialog(None, 'Which is your favorate name?', 'Single Choice', choice)
- if dlg.ShowModal() == wx.ID_OK:
- result = dlg.GetStringSelection()
- print result
- def evt_close(self, event):
- self.Destroy()
- class MyApp(wx.App):
- def __init__(self, redirect=True):
- wx.App.__init__(self, redirect)
- pass
-
- def OnInit(self):
- frame = MyFrame(None)
- frame.Show(True)
- self.SetTopWindow(frame)
- return True
-
- def OnExit(self):
- pass
- if __name__ == '__main__':
- app = MyApp()
- app.MainLoop()
复制代码
运行命令:
python filename
结果:当关闭窗口时,该程序仍不退出,CTRL+C 后才退出,终端才出现 '$' 提示符
如果把but_choose有关行去除,则正常退出!
why?
[ 本帖最后由 爱知 于 2008-12-27 10:52 编辑 ] |
|