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