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

标签 python widget gtk python-3.4

我正在使用 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/

相关文章:

将字符串转换为十六进制,如 "88"转换为 0x88

python - 在 df.pivot Python 中自定义列名称

c++ - Qt 线程计算输出到 GUI 中的自己的小部件?

audio - 显示 Windows 8 Metro 音量 slider /通知/小部件/指示器?

flutter - 如何在flutter中使Container的边框变成两种颜色?

python - 如何在python gtk中用图像填充按钮

gtk - 将 slider 添加到 AppIndicator (Ubuntu 11.04)

python - 如何使用 Python 运行 IOMeter?

python - 将默认参数定义为全局变量

python - KeyError ("word ' %s' 不在词汇表中"% word)