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

来源:互联网 发布:电脑音乐录音软件 编辑:程序博客网 时间:2024/06/07 03:11

  • GtkScaleButton
    • 继承关系
    • Methods
    • Virtual Methods
    • Properties
    • Signals
    • 例子

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 016TITLE = "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 gigi.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)        passdef 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.csdn.net/detail/a87b01c14/9594728

0 0