gpt4 book ai didi

python - GTK3 更改 Switch 小部件的按钮标签名称 'On' 和 'Off'

转载 作者:行者123 更新时间:2023-11-28 18:31:56 25 4
gpt4 key购买 nike

我正在使用 python3.4 和 gtk3,并且我一直在尝试找出是否可以将 Switch 小部件(“开”/“关”)的标签文本更改为其他内容,例如大多数小部件上的标签?

如果这不可能,我会觉得很疯狂,因为大多数其他小部件或按钮可以在大多数语言中更改其文本。

最佳答案

您可以通过子按钮访问它(“文本”是普通标签)

>>> btn = Gtk.Button('SomeText')
>>> btn.get_children()
[<Gtk.Label object at 0x7f70dd0c86c0 (GtkLabel at 0x2527340)>]

然后您可以将标签更改为例如:标记为

>>> btn.get_children()[0].set_use_markup(True)
>>> btn.get_children()[0].set_label("<span color='green'>TEST</span>")

来自 documentation :

The GtkButton widget can hold any valid child widget. That is, it can hold almost any other standard GtkWidget. The most commonly used child is the GtkLabel.

关于python - GTK3 更改 Switch 小部件的按钮标签名称 'On' 和 'Off',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36242280/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com