I have a button that will open a filechooser. But, I got this error:
(gui.py:9127): Gtk-CRITICAL **: gtk_widget_grab_default: assertion `gtk_widget_get_can_default (widget)' failed
(gui.py:9127): Gtk-CRITICAL **: _gtk_file_chooser_embed_initial_focus: assertion `GTK_IS_FILE_CHOOSER_EMBED (chooser_embed)' failed
This is my code:
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()
Do you know why this happen?
One more question: I have a file chooser button. How to make this button not to change path to (None)
when I click cancel if I already set path on it?
okay, I've got it. to resolve (gui.py:9127): Gtk-CRITICAL **: gtk_widget_grab_default: assertion 'gtk_widget_get_can_default (widget)' failed
, you should change can default
from Common Properties
of your filechooser buttons to Yes
.
and to resolve (gui.py:9127): Gtk-CRITICAL **: _gtk_file_chooser_embed_initial_focus: assertion 'GTK_IS_FILE_CHOOSER_EMBED (chooser_embed)' failed
, you should change filechooser.destroy()
to filechooser.hide()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.