PyGobject(十五)布局容器之Button篇——Gtk.ScaleButton

Gtk.ScaleButton

继承关系

Gtk.ScaleButton根据滑块位置,显示不同的图片。Gtk.ScaleButton是Gtk.Button的直接子类
这里写图片描述

Methods

方法修饰词方法名及参数
staticnew (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

NameTypeFlagsShort Description
adjustmentGtk.Adjustmentr/wScaleButton值的范围
icons[str]r/wList of icon names
sizeGtk.IconSizer/w/enThe icon size
valuefloatr/w/enThe value of the scale

Signals

NameShort Description
popdownThe ::popdown signal is a keybinding signal which gets emitted to popdown the scale widget.
popupThe ::popup signal is a keybinding signal which gets emitted to popup the scale widget.
value-changedThe ::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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sanxiaochengyu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值