Python 3.x Gtk消息对话框导致segfault(PYGObject)
我的程序有什么问题?它可以正常工作,直到它尝试显示对话框,然后再显示故障 如果解决方案显而易见,请原谅,这只是我的第二个GTK+计划Python 3.x Gtk消息对话框导致segfault(PYGObject),python-3.x,gtk,segmentation-fault,pygobject,Python 3.x,Gtk,Segmentation Fault,Pygobject,我的程序有什么问题?它可以正常工作,直到它尝试显示对话框,然后再显示故障 如果解决方案显而易见,请原谅,这只是我的第二个GTK+计划 import time, threading from sys import exit from gi.repository import Gtk, GObject def run_core_engine(): time.sleep(2) window.switchToMainFrame() time.sleep(2.5) wi
import time, threading
from sys import exit
from gi.repository import Gtk, GObject
def run_core_engine():
time.sleep(2)
window.switchToMainFrame()
time.sleep(2.5)
window.failDialog("The window said hello")
class CoreThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.daemon = True
super(CoreThread, self).start()
def run(self):
run_core_engine()
class GettingInfoFrame(Gtk.Frame):
def __init__(self):
Gtk.Frame.__init__(self)
self.connect("delete-event", Gtk.main_quit)
self.set_shadow_type(Gtk.ShadowType.NONE)
self.set_border_width(45)
vbox = Gtk.VBox(spacing=10)
hbox = Gtk.HBox(spacing=10)
text = Gtk.Label()
text.set_markup("<b><big>Doing stuff...</big></b>")
self.spinner = Gtk.Spinner()
self.spinner.set_size_request(30, 30)
self.spinner.start()
hbox.pack_start(text, True, True, 10)
hbox.pack_start(self.spinner, True, True, 10)
vbox.pack_start(hbox, True, True, 10)
self.add(vbox)
class TheMainFrame(Gtk.Frame):
def __init__(self):
Gtk.Frame.__init__(self)
self.set_shadow_type(Gtk.ShadowType.NONE)
self.set_border_width(150)
label = Gtk.Label("Hello")
box = Gtk.VBox()
box.pack_start(label, True, True, 0)
self.add(box)
class Window(Gtk.Window):
def __init__(self):
## Setup Main Window
Gtk.Window.__init__(self, title="Fred the window")
self.connect("delete-event", Gtk.main_quit)
self.set_resizable(False)
self.gettingInfoFrame = GettingInfoFrame()
self.add(self.gettingInfoFrame)
def switchToMainFrame(self):
print("Displaying information in window")
self.theMainFrame = TheMainFrame()
self.remove(self.get_child())
self.add(self.theMainFrame)
self.show_all()
def failDialog(self, message):
dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO,
Gtk.ButtonsType.OK, "INFO:")
dialog.format_secondary_text(message)
dialog.run() **# <-- Where the error occurs**
Gtk.main_quit()
GObject.threads_init()
core_thread = CoreThread()
window = Window()
window.show_all()
Gtk.main()
导入时间,线程
从系统导入退出
从gi.repository导入Gtk,GObject
def run_core_发动机():
时间。睡眠(2)
window.switchToMainFrame()
时间。睡眠(2.5)
failDialog(“窗口说你好”)
类芯螺纹(螺纹.螺纹):
定义初始化(自):
threading.Thread.\uuuuu init\uuuuuu(自)
self.daemon=True
super(CoreThread,self).start()
def运行(自):
运行核心引擎()
类GettingInfoFrame(Gtk.Frame):
定义初始化(自):
Gtk.Frame._初始__(自)
self.connect(“删除事件”,Gtk.main_退出)
self.set_shadow_type(Gtk.ShadowType.NONE)
自设置边框宽度(45)
vbox=Gtk.vbox(间距=10)
hbox=Gtk.hbox(间距=10)
text=Gtk.Label()
text.set_标记(“做事…”)
self.spinner=Gtk.spinner()
self.spinner.set\u size\u请求(30,30)
self.spinner.start()
hbox.pack_start(文本,真,真,10)
hbox.pack_start(self.spinner,True,True,10)
vbox.pack_start(hbox,True,True,10)
self.add(vbox)
将主框架(Gtk.Frame)分类:
定义初始化(自):
Gtk.Frame._初始__(自)
self.set_shadow_type(Gtk.ShadowType.NONE)
自设置边框宽度(150)
label=Gtk.label(“你好”)
box=Gtk.VBox()
box.pack_start(标签,真,真,0)
self.add(框)
类窗口(Gtk.Window):
定义初始化(自):
##设置主窗口
Gtk.Window.uu init_uuu(self,title=“Fred the Window”)
self.connect(“删除事件”,Gtk.main_退出)
self.set_可调整大小(False)
self.gettingInfoFrame=gettingInfoFrame()
self.add(self.gettingInfoFrame)
def切换到Inframe(自身):
打印(“在窗口中显示信息”)
self.theMainFrame=theMainFrame()
self.remove(self.get_child())
self.add(self.theMainFrame)
self.show_all()
def故障对话框(自我,消息):
dialog=Gtk.MessageDialog(self,0,Gtk.MessageType.INFO,
Gtk.buttonType.OK,“信息:”)
对话框。格式化辅助文本(消息)
dialog.run()**#直接获取宽度,而不是使用
gtk_小部件_获取_宽度
(2ndgtk+.py:32073):Gtk警告**:GtkBox 0x7ff514004080:小部件
试图在GtkWidget::get_width中获取gtk_widget_width
实施应该只调用
GTK_WIDGET_GET_CLASS(WIDGET)->直接获取宽度,而不是使用
gtk_小部件_获取_宽度
(2ndgtk+.py:32073):Gtk警告**:Gtk按钮框0x2170620:小部件
试图在GtkWidget::get_width中获取gtk_widget_width
实施应该只调用
GTK_WIDGET_GET_CLASS(WIDGET)->直接获取宽度,而不是使用
gtk_小部件_获取_宽度
(2ndgtk+.py:32073):Gtk警告**:Gtk按钮0x7ff514010050:小部件
试图在GtkWidget::get_height中获取gtk_widget_height
实施应该只调用
GTK_WIDGET_GET_CLASS(WIDGET)->直接获取高度,而不是使用
gtk_小部件_获取_高度
(2ndgtk+.py:32073):Gtk警告**:Gtk信号0x7ff514014070:
widget试图在GtkWidget内获得gtk_widget_高度
::获取高度实现。应该只调用
GTK_WIDGET_GET_CLASS(WIDGET)->直接获取高度,而不是使用
gtk_小部件_获取_高度
(2ndgtk+.py:32073):Gtk警告**:GtkBox 0x7ff514004320:小部件
试图在GtkWidget::get_height中获取gtk_widget_height
实施应该只调用
GTK_WIDGET_GET_CLASS(WIDGET)->直接获取高度,而不是使用
gtk_小部件_获取_高度
(2ndgtk+.py:32073):Gtk警告**:GtkLabel 0x22a2ac0:小部件已尝试
要在GtkWidget::get_height中获取gtk_小部件的高度,请执行以下操作
实施应该只调用
GTK_WIDGET_GET_CLASS(WIDGET)->直接获取高度,而不是使用
gtk_小部件_获取_高度分段错误
我想出来了。问题是直接调用“window.failDialog”,而不是使用GLib.idle\u add。
我添加了一些其他的细微变化
以下是新代码:
import time, threading
from sys import exit
from gi.repository import Gtk, GObject, GLib
def run_core_engine():
time.sleep(2)
window.switchToMainFrame()
time.sleep(2.5)
GLib.idle_add(window.failDialog, "The window said hello")
class CoreThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.daemon = True
super(CoreThread, self).start()
def run(self):
run_core_engine()
class GettingInfoFrame(Gtk.Frame):
def __init__(self):
Gtk.Frame.__init__(self)
self.connect("delete-event", Gtk.main_quit)
self.set_shadow_type(Gtk.ShadowType.NONE)
self.set_border_width(45)
vbox = Gtk.VBox(spacing=10)
hbox = Gtk.HBox(spacing=10)
text = Gtk.Label()
text.set_markup("<b><big>Doing stuff...</big></b>")
self.spinner = Gtk.Spinner()
self.spinner.set_size_request(30, 30)
self.spinner.start()
hbox.pack_start(text, True, True, 10)
hbox.pack_start(self.spinner, True, True, 10)
vbox.pack_start(hbox, True, True, 10)
self.add(vbox)
class TheMainFrame(Gtk.Frame):
def __init__(self):
Gtk.Frame.__init__(self)
self.set_shadow_type(Gtk.ShadowType.NONE)
self.set_border_width(150)
label = Gtk.Label("Hello")
box = Gtk.VBox()
box.pack_start(label, True, True, 0)
self.add(box)
class Window(Gtk.Window):
def __init__(self):
## Setup Main Window
Gtk.Window.__init__(self, title="Fred the window")
self.connect("delete-event", Gtk.main_quit)
self.set_resizable(False)
self.gettingInfoFrame = GettingInfoFrame()
self.add(self.gettingInfoFrame)
def switchToMainFrame(self):
print("Displaying information in window")
self.theMainFrame = TheMainFrame()
self.remove(self.get_child())
self.add(self.theMainFrame)
self.show_all()
def failDialog(self, errorMessage):
dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO,
Gtk.ButtonsType.OK, "INFO:")
dialog.format_secondary_text(errorMessage)
dialog.run()
Gtk.main_quit()
GObject.threads_init()
core_thread = CoreThread()
window = Window()
window.show_all()
Gtk.main()
导入时间,线程
从系统导入退出
从gi.repository导入Gtk、GObject、GLib
def run_core_发动机():
时间。睡眠(2)
window.switchToMainFrame()
时间。睡眠(2.5)
GLib.idle\u add(window.failDialog,“窗口打招呼”)
类芯螺纹(螺纹.螺纹):
定义初始化(自):
threading.Thread.\uuuuu init\uuuuuu(自)
self.daemon=True
super(CoreThread,self).start()
def运行(自):
运行核心引擎()
类GettingInfoFrame(Gtk.Frame):
定义初始化(自):
Gtk.Frame._初始__(自)
self.connect(“删除事件”,Gtk.main_退出)
self.set_shadow_type(Gtk.ShadowType.NONE)
自设置边框宽度(45)
vbox=Gtk.vbox(间距=10)
hbox=Gtk.hbox(间距=10)
text=Gtk.Label()
text.set_标记(“做事…”)
self.spinner=Gtk.spinner()
self.spinner.set\u size\u请求(30,30)
self.spinner.start()
hbox.pack_start(文本,真,真,10)
hbox.pack_start(self.spinner,True,True,10)
vbox.pack_start(hbox,True,True,10)
self.add(vbox)
将主框架(Gtk.Frame)分类:
定义初始化(自):
Gtk.Frame._初始__(自)
self.set_shadow_type(Gtk.ShadowType.NONE)
自设置边框宽度(150)
label=Gtk.label(“你好”)
box=Gtk.VBox()
box.pack_start(标签,真,真,0)
self.add(框)
类窗口(Gtk.Window):
定义初始化(自):
##设置主窗口
Gtk.Window.uu init_uuu(self,title=“Fred the Window”)
self.connect(“删除事件”,Gtk.main_退出)
self.set_可调整大小(False)
self.gettingInfoFrame=gettingInfoFrame()
自己