2
如何正确创建Gtk.FileChooseDialog?Python GTK3:如何创建一个Gtk.FileChooseDialog?
This popular tutorial说,使用类似下面的代码:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
dialog = Gtk.FileChooserDialog("Please choose a folder", None,
Gtk.FileChooserAction.SELECT_FOLDER,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
"Select", Gtk.ResponseType.OK))
但是,如果你运行这个与python -W error
(赶弃用警告),它说:
File "test3.py", line 8, in <module>
"Select", Gtk.ResponseType.OK))
File "/usr/lib/python2.7/dist-packages/gi/overrides/__init__.py", line 287, in new_init
category, stacklevel=stacklevel)
gi.overrides.Gtk.PyGTKDeprecationWarning: Using positional arguments with the GObject constructor has been deprecated. Please specify keyword(s) for "title, parent, action, buttons" or use a class specific constructor. See: https://wiki.gnome.org/PyGObject/InitializerDeprecations
使用Gtk.FileChooserDialog.new
给TypeError: Dialog constructor cannot be used to create instances of a subclass FileChooserDialog
。
The API对构造函数没有提及。奇怪的。
ps:此问题的答案应与python -W error
一起使用。它不应该依赖于已弃用的API。这是我问的所有问题。