致电glfw.init()之后,Badwindow在TKINTER中崩溃
我有以下代码,它可以在 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 上一样运行?
I have the following code, which works on Windows, but crashes on Linux with X11:
#! /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()
After clicking OK in the message box on Linux/X11, the program crashes with:
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
The addresses vary after each run, but the overall error stays the same.
I was able to reduce the problem to the call of glfw.init()
which results in subsequent closing of tkinter Windows to crash the program. However, this does not happen on Windows systems.
Some system info:
$ 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
Why is this program crashing on my system?
What can I do to make it run just like on windows?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是这方面的专家,但如果您只想拥有工作代码,则必须在
super().__init__()
之前调用glfw.init()
,例如这个:我认为最好将
glfw.init()
放在main
之前MainWindow().mainloop()
,但我想为了表明我认为问题直接出在super().__ini__()
。我没有测试 glfw 的任何功能,我只是检查了这个,因为 有关 SO 的其他问题
这里有一些您可以检查的链接,也许它们可以提供帮助:
togl
代码项目
I'm not an expert on this, but if you only want to have working code you have to call
glfw.init()
beforesuper().__init__()
like this:I think it is better to put the
glfw.init()
inmain
beforeMainWindow().mainloop()
, but i wanted to make clear that i think the problem is directly insuper().__ini__()
.I did not tested any function of glfw, i only checked this because of other questions on SO
Here are some links you can check, maybe they can help:
togl
code project