python - 模式对话框卡住整个应用程序

标签 python matplotlib wxpython

我在 ubuntu 机器上将 wxpython 与 matplotlib 后端一起使用。我想将我的 matplotlib Canvas 连接到弹出 wxpython 模式对话框的 button_press_event 。当模式对话框弹出时,整个应用程序被卡住。 Windows 机器上不会出现此问题。这是通常重现问题的代码片段。

import wx

from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
from matplotlib.figure import Figure


class SettingDialog(wx.Dialog):

    def __init__(self, parent=None):

        wx.Dialog.__init__(self, parent, wx.ID_ANY, title="Modal dialog")


class PlotterFrame(wx.Frame):

    def __init__(self, parent, title="Frame with matplotlib canvas"):

        wx.Frame.__init__(self, parent, wx.ID_ANY, title)

        self.figure = Figure(figsize=(5,4), dpi=None)
        self.canvas = FigureCanvasWxAgg(self, -1, self.figure )
        self.canvas.mpl_connect("button_press_event", self.on_click)


    def on_click(self, event=None):
        d = SettingDialog(self)
        d.ShowModal()
        d.Destroy()  

if __name__ == "__main__":
    app = wx.App(False)
    f = PlotterFrame(None)
    f.Show()
    app.MainLoop()

您知道我的代码有什么问题吗?

PS0:问题是对话框窗口也被卡住,就像桌面上的所有应用程序不再使用react一样。唯一的逃避方法是使用键盘切换到另一个桌面

PS1:有一个非常常见的例子,如 http://eli.thegreenplace.net/files/prog_code/wx_mpl_bars.py.txt 问题也出现了,我的结论是,这个问题是Linux(这里是ubuntu 12.04)上以下库版本的一个错误: wx.版本:'2.8.12.1' matplotlib.版本:'1.1.1rc'

最佳答案

模式对话框的全部要点是,当对话框处于模式状态时,它会卡住应用程序。如果您不希望应用程序卡住,则不要以模态方式显示对话框。

关于python - 模式对话框卡住整个应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16815695/

相关文章:

python - 如何将 Google 日历的 "Private Address"与 gdata.calendar.service 一起使用?

python - 如何停止在 csv 文件末尾写一个空行 - pandas

python - matplotlib 中的离散数据图

python - 同一 3D 轴中的多条独立线

python - 动态改变 wx.TextCtrl 的大小

python - 如何更改 wxPython 工具栏的外观?

python - 在 python 中从 SQLite 数据库检索值的一些错误

python dataframe 做类似 oracle connect_by 的事情吗?

python - Matplotlib:annotate() 缺少 1 个必需的位置参数: 'self'

python - 从消息对话框中删除蜂鸣声