import wx
'''
从一个列表中选择
'''
app=wx.App(False)
frame= wx.Frame(None, -1, "Single Choice")
dlg=wx.SingleChoiceDialog(None,"what version of Python are you using?",
"Single Choice",
["1.5.2", "2.0", "2.1.3", "2.2", "2.3.1"])
if dlg.ShowModal()==wx.ID_OK:
response=dlg.GetStringSelection()
print response
frame.Show()
app.MainLoop()
print "hello"
===========================================
运行程序,发现程序无法卡死,并且无法回到Shell控制台。原因在于我们创建了一个wx.SingleChoiceDialog的列表单选框dlg控件,但是并没有并我们关闭掉,导致wxPython是一直有控件在运行的。所以关闭掉dlg然后清除掉dlg,程序才可以回到Shell控制台。
修改后的程序:
import wx
'''
从一个列表中选择
'''
app=wx.App(False)
frame= wx.Frame(None, -1, "Single Choice")
dlg=wx.SingleChoiceDialog(None,"what version of Python are you using?",
"Single Choice",
["1.5.2", "2.0", "2.1.3", "2.2", "2.3.1"])
if dlg.ShowModal()==wx.ID_OK:
response=dlg.GetStringSelection()
print response
frame.Show()
dlg.Destroy() # 打开一个对话框必须清掉(Destroy)
app.MainLoop()
print "hello"
===================================
完美解决TnT