如何在 Gtk.FileChooser 中启用 Gtk.SpinButton?

How can I enable a Gtk.SpinButton in a Gtk.FileChooser?

在我的应用程序中,我想为图像做一个保存机制。 为此,我使用 Gtk.FileChooserDialog 到 select 新文件的位置。它工作正常,但我也希望能够 select 图像的大小(宽度和高度)。

我为此使用 Gtk.Spinbutton 并将它们添加到我的对话框的 content_area 中,然后我强制显示它。 小部件显示正常,但我无法像普通人那样进行交互 Gtk.Spinbutton:我无法通过滚动或单击递增/递减按钮来更改值。

我仍然可以通过在条目中键入来更改值。

显示问题的代码:

from gi.repository import Gtk

class Window(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)

        self.connect("destroy", self.on_destroy)

        self.set_icon_name("applications-development")
        self.show_all()

        dialog = Gtk.FileChooserDialog(
            transient_for = self,
            buttons = (
                Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                Gtk.STOCK_SAVE, Gtk.ResponseType.OK
            )
        )

        spinbutton = Gtk.SpinButton()
        spinbutton.set_range(0, 10)
        spinbutton.set_value(5)
        spinbutton.show()

        dialog.get_content_area().pack_start(spinbutton, True, False, 0)

        dialog.run()
        dialog.hide()

    def on_destroy(self, *args):
        Gtk.main_quit()

Window()
Gtk.main()

在 python 版本 2.7.63.4.3 中都会出现此错误。

未指定两个按钮的步骤。所以你可以这样做:

spinbutton = Gtk.SpinButton()
spinbutton.set_range(0, 10)
spinbutton.set_increments(1, -1)
spinbutton.set_value(5)
spinbutton.show()

或:

spinbutton = Gtk.SpinButton.new_with_range(0, 10, 1)
spinbutton.set_value(5)
spinbutton.show()