wx“简单的图形用户界面”图书馆;我如何防止此代码崩溃 IDLE &其他 Python IDE?
当我在 IDLE 中运行此代码时,它崩溃了。但是,如果我在 IDLE 之外运行它,它就可以正常工作。
有几个用 python 编写的 Python IDE 也遇到同样的问题,但如果我使用不基于它的 IDE/编辑器,它们也可以正常运行。
有没有办法修改这段代码,这样它就不会搞乱 IDLE & 了。朋友们?
import wx
def MultiChoiceDialog(parent, title, message, choices):
app = wx.PySimpleApp()
app.MainLoop()
dlg = wx.MultiChoiceDialog(parent, title, message, choices)
try:
if dlg.ShowModal() == wx.ID_OK:
selections = dlg.GetSelections()
strings = [choices[x] for x in selections]
return strings
else:
return False
finally:
dlg.Destroy()
app.Destroy()
哦,如果还不是很明显,我将其导入到另一个文件中,并像这样调用 MultiChoiceDialog:
#Choice = MultiChoiceDialog(None, 'Title', 'Message', ['game1', 'game2', 'game3'])
When I run this code in IDLE, it crashes. However, if I run it outside of IDLE it works just fine.
There are a couple of Python IDEs that are written in python that suffer the same problem, but if I use an IDE/editor that's not based on it, those run fine as well.
Is there any way of modifying this code so it doesn't muck up IDLE & Friends?
import wx
def MultiChoiceDialog(parent, title, message, choices):
app = wx.PySimpleApp()
app.MainLoop()
dlg = wx.MultiChoiceDialog(parent, title, message, choices)
try:
if dlg.ShowModal() == wx.ID_OK:
selections = dlg.GetSelections()
strings = [choices[x] for x in selections]
return strings
else:
return False
finally:
dlg.Destroy()
app.Destroy()
Oh, and if it's not already obvious, I'm importing this in another file, and calling MultiChoiceDialog like so:
#Choice = MultiChoiceDialog(None, 'Title', 'Message', ['game1', 'game2', 'game3'])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Ubuntu 上最新版本的 IDLE (2.7.2) 和 wx 2.8.11.0 不会导致 IDLE 崩溃。
The most recent version of IDLE (2.7.2) with wx 2.8.11.0 on Ubuntu does not crash IDLE.