python - 调用 glfw.init() 后,BadWindow 在 tkinter 中崩溃

标签 python linux tkinter x11 glfw

我有以下代码,它可以在 Windows 上运行,但在带有 X11 的 Linux 上崩溃:

#! /usr/bin/env python3
"""Tkinter crashes on X11 when popup windows
are closed after calling glfw.init()
"""

from sys import exit

from tkinter import Tk
from tkinter.messagebox import showinfo

from glfw import init


class MainWindow(Tk):
    """Main window."""

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        if not init():
            exit(2)

        showinfo('Close me', 'I dare you')


def main():
    """Run the script."""

    MainWindow().mainloop()


if __name__ == '__main__':
    main()

在 Linux/X11 上的消息框中单击确定后,程序崩溃并显示:

X Error of failed request:  BadWindow (invalid Window parameter)
  Major opcode of failed request:  15 (X_QueryTree)
  Resource id in failed request:  0x4c0000a
  Serial number of failed request:  778
  Current serial number in output stream:  778

每次运行后地址都会有所不同,但总体错误保持不变。
我能够将问题简化为调用 glfw.init() ,这会导致随后关闭 tkinter Windows 以使程序崩溃。但是,这在 Windows 系统上不会发生。

一些系统信息:

$ uname -r
5.16.16-arch1-1
$ pacman -Q xorg-server
xorg-server 21.1.3-6
$ echo $XDG_SESSION_TYPE
x11
$ pacman -Q glfw python-glfw
glfw-x11 3.3.6-1
python-glfw 2.1.0-2

为什么这个程序在我的系统上崩溃?
我该怎么做才能让它像在 Windows 上一样运行?

最佳答案

我不是这方面的专家,但如果您只想拥有工作代码,则必须调用 glfw.init()之前super().__init__()像这样:

from tkinter import Tk
from tkinter.messagebox import showinfo

from glfw import init


class MainWindow(Tk):
    """Main window."""

    def __init__(self, *args, **kwargs):
        if not init():
            exit(2)
        super().__init__(*args, **kwargs)

        showinfo('Close me', 'I dare you')


def main():
    """Run the script."""
    MainWindow().mainloop()


if __name__ == '__main__':
    main()

我认为最好把 glfw.init()main之前MainWindow().mainloop() ,但我想澄清的是,我认为问题直接出在 super().__ini__() 中。 .

我没有测试glfw的任何功能,我只是因为other questions on SO才检查了这个

以下是一些您可以查看的链接,也许它们可以提供帮助: togl code project

关于python - 调用 glfw.init() 后,BadWindow 在 tkinter 中崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71649848/

相关文章:

python - 递归映射对角线元素并检查条件,Python

linux - 简单的 Docker 概念

python - 在 tk.Entry textvariable 上调用 tk.StringVar.set() 会导致 validate ="focusout"停止被调用

python - 播放音频文件后 pygame 没有响应

python - 如何获得 Plotly 图的 x 轴范围?

python - python模拟模块是否通过依赖注入(inject)工作?

python - 反转附加列表或前置列表是否更便宜? - Python

php - 从 file1 file2 获取公共(public)数据的 comm 命令

Linux 内核 : how to force TCP RST to be sent on incoming interface and not making routing decisions?

python - 从字符串中删除 "\n",但保留实际的换行符?