Gtk.ScaleButton
继承关系
Gtk.ScaleButton根据滑块位置,显示不同的图片。Gtk.ScaleButton是Gtk.Button的直接子类
Methods
方法修饰词 | 方法名及参数 |
---|---|
static | new (size, min, max, step, icons) |
get_adjustment () | |
get_minus_button () | |
get_plus_button () | |
get_popup () | |
get_value () | |
set_adjustment (adjustment) | |
set_icons (icons) | |
set_value (value) |
Virtual Methods
do_value_changed (value) |
Properties
Name | Type | Flags | Short Description |
---|---|---|---|
adjustment | Gtk.Adjustment | r/w | ScaleButton值的范围 |
icons | [str] | r/w | List of icon names |
size | Gtk.IconSize | r/w/en | The icon size |
value | float | r/w/en | The value of the scale |
Signals
Name | Short Description |
---|---|
popdown | The ::popdown signal is a keybinding signal which gets emitted to popdown the scale widget. |
popup | The ::popup signal is a keybinding signal which gets emitted to popup the scale widget. |
value-changed | The ::value-changed signal is emitted when the value field has changed. |
例子
代码:
#!/usr/bin/env python3
# Created by xiaosanyu at 16/6/27
# section 016
TITLE = "ScaleButton"
DESCRIPTION = """
Gtk.ScaleButton provides a button which pops up a scale widget.
This kind of widget is commonly used for volume controls in multimedia applications,
and GTK+ provides a Gtk.VolumeButton subclass that is tailored for this use case.
"""
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# 最高的图标要放在第二位
icons = ["microphone-sensitivity-muted-symbolic.symbolic", "microphone-sensitivity-high-symbolic.symbolic",
"microphone-sensitivity-low-symbolic.symbolic", "microphone-sensitivity-medium-symbolic.symbolic"]
class ScaleButtonWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="ScaleButton Demo")
self.set_border_width(10)
self.set_default_size(200, 300)
box = Gtk.Box()
sbtn = Gtk.ScaleButton(icons=icons)
sbtn.connect("value_changed", self.change)
box.add(sbtn)
self.add(box)
def change(self, btn, value):
# print(value)
pass
def main():
win = ScaleButtonWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
if __name__ == "__main__":
main()
分析主要代码
定义显示的图片名称列表,默认显示的放在第一个,最后显示的图片放第二个,其余依次排放
icons =
["microphone-sensitivity-muted-symbolic.symbolic",
"microphone-sensitivity-high-symbolic.symbolic",
"microphone-sensitivity-low-symbolic.symbolic", "microphone-sensitivity-medium-symbolic.symbolic"]
定义一个ScaleButton,指定其icons属性
sbtn = Gtk.ScaleButton(icons=icons)
绑定”value_changed”信号
sbtn.connect("value_changed", self.change)
代码下载地址:http://download.youkuaiyun.com/detail/a87b01c14/9594728