如何避免由Tkinter,visual和ipython引起的Gdk-ERROR?

时间:2023-01-24 14:05:13

The following lines cause with ipython a crash as soon as I close the tk-window instance a.

一旦关闭tk窗口实例a,以下行导致ipython崩溃。

import visual, Tkinter
a = Tkinter.Tk()
a.update()
display = visual.display(title = "Hallo")
display.exit = 0
visual.sphere()

If I close the visual display first, the entire terminal crashes. I run everything on kubuntu 8.10. Is this a bug or am I doing something wrong? If this is a bug: Is there a smart way to avoid it?

如果我先关闭可视显示器,整个终端都会崩溃。我在kubuntu 8.10上运行一切。这是一个错误还是我做错了什么?如果这是一个错误:有没有一种聪明的方法来避免它?

Cheers, Philipp

1 个解决方案

#1


Have you tried starting ipython with the -gthread -tk command-line switches?

您是否尝试使用-gthread -tk命令行开关启动ipython?

From ipython --help:

来自ipython --help:

       -gthread, -qthread, -q4thread, -wthread, -pylab

              Only ONE of these can be given, and it can only be given as the
              first option passed to IPython (it will have no effect in any
              other position).  They provide threading support for the GTK, QT
              and WXWidgets toolkits, and for the matplotlib library.

              With any of the first four options, IPython starts running a
              separate thread for the graphical toolkit's operation, so that
              you can open and control graphical elements from within an
              IPython command line, without blocking.  All four provide
              essentially the same functionality, respectively for GTK, QT3,
              QT4 and WXWidgets (via their Python interfaces).

              Note that with -wthread, you can additionally use the -wxversion
              option to request a specific version of wx to be used.  This
              requires that you have the 'wxversion' Python module installed,
              which is part of recent wxPython distributions.

              If -pylab is given, IPython loads special support for the mat-
              plotlib library (http://matplotlib.sourceforge.net), allowing
              interactive usage of any of its backends as defined in the
              user's .matplotlibrc file.  It automatically activates GTK, QT
              or WX threading for IPyhton if the choice of matplotlib backend
              requires it.  It also modifies the %run command to correctly
              execute (without blocking) any matplotlib-based script which
              calls show() at the end.

       -tk    The -g/q/q4/wthread options, and -pylab (if matplotlib is
              configured to use GTK, QT or WX), will normally block Tk
              graphical interfaces.  This means that when GTK, QT or WX
              threading is active, any attempt to open a Tk GUI will result in
              a dead window, and possibly cause the Python interpreter to
              crash.  An extra option, -tk, is available to address this
              issue.  It can ONLY be given as a SECOND option after any of the
              above (-gthread, -qthread, q4thread, -wthread or -pylab).

              If -tk is given, IPython will try to coordinate Tk threading
              with GTK, QT or WX.  This is however potentially unreliable, and
              you will have to test on your platform and Python configuration
              to determine whether it works for you.  Debian users have
              reported success, apparently due to the fact that Debian builds
              all of Tcl, Tk, Tkinter and Python with pthreads support.  Under
              other Linux environments (such as Fedora Core 2/3), this option
              has caused random crashes and lockups of the Python interpreter.
              Under other operating systems (Mac OSX and Windows), you'll need
              to try it to find out, since currently no user reports are
              available.

              There is unfortunately no way for IPython to determine  at  run-
              time  whether -tk will work reliably or not, so you will need to
              do some experiments before relying on it for regular work.

#1


Have you tried starting ipython with the -gthread -tk command-line switches?

您是否尝试使用-gthread -tk命令行开关启动ipython?

From ipython --help:

来自ipython --help:

       -gthread, -qthread, -q4thread, -wthread, -pylab

              Only ONE of these can be given, and it can only be given as the
              first option passed to IPython (it will have no effect in any
              other position).  They provide threading support for the GTK, QT
              and WXWidgets toolkits, and for the matplotlib library.

              With any of the first four options, IPython starts running a
              separate thread for the graphical toolkit's operation, so that
              you can open and control graphical elements from within an
              IPython command line, without blocking.  All four provide
              essentially the same functionality, respectively for GTK, QT3,
              QT4 and WXWidgets (via their Python interfaces).

              Note that with -wthread, you can additionally use the -wxversion
              option to request a specific version of wx to be used.  This
              requires that you have the 'wxversion' Python module installed,
              which is part of recent wxPython distributions.

              If -pylab is given, IPython loads special support for the mat-
              plotlib library (http://matplotlib.sourceforge.net), allowing
              interactive usage of any of its backends as defined in the
              user's .matplotlibrc file.  It automatically activates GTK, QT
              or WX threading for IPyhton if the choice of matplotlib backend
              requires it.  It also modifies the %run command to correctly
              execute (without blocking) any matplotlib-based script which
              calls show() at the end.

       -tk    The -g/q/q4/wthread options, and -pylab (if matplotlib is
              configured to use GTK, QT or WX), will normally block Tk
              graphical interfaces.  This means that when GTK, QT or WX
              threading is active, any attempt to open a Tk GUI will result in
              a dead window, and possibly cause the Python interpreter to
              crash.  An extra option, -tk, is available to address this
              issue.  It can ONLY be given as a SECOND option after any of the
              above (-gthread, -qthread, q4thread, -wthread or -pylab).

              If -tk is given, IPython will try to coordinate Tk threading
              with GTK, QT or WX.  This is however potentially unreliable, and
              you will have to test on your platform and Python configuration
              to determine whether it works for you.  Debian users have
              reported success, apparently due to the fact that Debian builds
              all of Tcl, Tk, Tkinter and Python with pthreads support.  Under
              other Linux environments (such as Fedora Core 2/3), this option
              has caused random crashes and lockups of the Python interpreter.
              Under other operating systems (Mac OSX and Windows), you'll need
              to try it to find out, since currently no user reports are
              available.

              There is unfortunately no way for IPython to determine  at  run-
              time  whether -tk will work reliably or not, so you will need to
              do some experiments before relying on it for regular work.