如何在GTK文件选择器对话框中解决此错误

时间:2013-06-12 06:20:02

标签: python gtk filechooser

我有一个打开文件追踪器的按钮。但是,我收到了这个错误:

  

(gui.py:9127):Gtk-CRITICAL **:gtk_widget_grab_default:断言   `gtk_widget_get_can_default(widget)'失败

     

(gui.py:9127):Gtk-CRITICAL **:_gtk_file_chooser_embed_initial_focus:   断言`GTK_IS_FILE_CHOOSER_EMBED(chooser_embed)'失败

这是我的代码:

from gi.repository import Gtk

def clicked(widget):
    response = filechooser.run()
    if response == Gtk.ResponseType.OK:
        print 'ok'
    else:
        print 'cancel'
        filechooser.destroy()

builder = Gtk.Builder()
builder.add_from_file('gui.glade')
filechooser = builder.get_object('filechooser1')
builder.get_object('button1').connect('clicked', clicked)
builder.get_object('window1').show_all()
Gtk.main()

你知道为什么会这样吗?

还有一个问题: 我有一个文件选择按钮。如果我已单击取消,如果我已在其上设置路径,如何使此按钮不更改(None)的路径?

1 个答案:

答案 0 :(得分:6)

好吧,我已经明白了。要解决(gui.py:9127): Gtk-CRITICAL **: gtk_widget_grab_default: assertion 'gtk_widget_get_can_default (widget)' failed,您应该将can defaultCommon Properties的文件追踪器按钮更改为Yes

要解决(gui.py:9127): Gtk-CRITICAL **: _gtk_file_chooser_embed_initial_focus: assertion 'GTK_IS_FILE_CHOOSER_EMBED (chooser_embed)' failed,您应该将filechooser.destroy()更改为filechooser.hide()