wx“简单的图形用户界面”图书馆;我如何防止此代码崩溃 IDLE &其他 Python IDE?

发布于 2024-08-19 17:21:01 字数 823 浏览 1 评论 0原文

当我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的他你的她 2024-08-26 17:21:01

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文