PyGObject无论如何都会固定按钮大小。相应地拆分标签

2022-02-27 00:00:00 python python-3.x gtk3 gtk pygobject

问题描述

我正在使用PyGObject创建均匀的按钮网格。当前,y我这样做是为了调整按钮大小和添加按钮。

folder_button = Gtk.Button(label=folder["label"])
folder_button.set_size_request(64,64)
folder_button.set_hexpand(False)
self.attach(folder_button,folder["column"],folder["row"],1,1)

如果按钮标签足够小,可以放在按钮内部,那么就没有问题。但是,如果我有更长的标签,按钮会扩展以适合标签。我想停止这种扩展,并相应地打断/缩放/截断标签。执行此操作的最佳方式是什么?


解决方案

您可以ellipsize放在中间。示例:

label = Gtk.Label("This text is absolutely terribly too long to "
                        "fit in any decent size space on a normal window "
                        "anybody in his right mind would be using, so "
                        "please ellipsize it using a Gtk function that "
                        "calculates a decent size based on the rest of "
                        "the window by using some dots in the middle of "
                        "the text. Thank You!")
label.set_ellipsize (Pango.EllipsizeMode.MIDDLE)
folder_button = Gtk.Button(label=label)

相关文章