如何修复GTK / LibHandy代码段的Gtk.ListBox中的大按钮开关>>

问题描述 投票:0回答:1

使用python,gtk和libhandy创建了一个简单的列表框。不幸的是,我不知道为什么开关盒这么大(丑陋)。它们看起来根本不自然。

gi.require_version('Handy', '0.0')
gi.require_version('Gtk', '3.0')

from gi.repository import Gtk, Handy


class MyWindow(Gtk.Window):

    def __init__(self):

            # https://lazka.github.io/pgi-docs/Gtk-3.0/classes/Window.html
        Gtk.Window.__init__(self)

        self.set_title("Switches Example")
        self.connect("destroy", Gtk.main_quit)
        self.set_size_request(350, 350)

            # Create List Box
            # https://lazka.github.io/pgi-docs/Gtk-3.0/classes/ListBox.html 
        box = Gtk.ListBox()
        box.set_selection_mode(Gtk.SelectionMode.NONE)

            # use the libhandy function to add separators to listbox rows
            # https://lazka.github.io/pgi-docs/#Handy-0.0/functions.html#Handy.list_box_separator_header
        box.set_header_func(Handy.list_box_separator_header)

            # Add some rows
        box.add(self.addrow("London"))
        box.add(self.addrow("Berlin"))
        box.add(self.addrow("Prague"))

            # Add List box to main window
        self.add(box)


    def addrow(self, title):

            # https://lazka.github.io/pgi-docs/#Handy-0.0/classes/ActionRow.html
        row = Handy.ActionRow()
        row.set_title(title)

            # Add action to row
        row.add_action(Gtk.Switch.new())
        return row

    # https://lazka.github.io/pgi-docs/#Handy-0.0/functions.html#Handy.init 
Handy.init()

window = MyWindow()
window.show_all()
Gtk.main()

当前,开关按钮看起来像这样(又大又丑)。Current

这是预期的外观Expected

如何使开关按钮看起来像预期的一样?

使用python,gtk和libhandy创建了一个简单的列表框。不幸的是,我不知道为什么开关盒这么大(丑陋)。它们看起来根本不自然。 gi.require_version('Handy','0 ....

python gtk gtk3 pygtk
1个回答
0
投票

您需要将valignGtk.Switch属性设置为Gtk.Align.CENTER,默认为Gtk.Align.FILL

© www.soinside.com 2019 - 2024. All rights reserved.