PyGobject(六十九)Gtk.Widget之Gtk.LevelBar

本文介绍 Gtk.LevelBar 的使用方法,这是一种类似于 Gtk.ProgressBar 的进度条组件,但不显示文本。文章通过一个 Python 示例展示了如何创建并更新 Gtk.LevelBar 的值,并介绍了其主要属性和信号。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Gtk.LevelBar

Gtk.LevelBar进度条。有点类似如Gtk.ProgressBar,不过它不显示文本

继承关系

这里写图片描述

Methods

方法修饰词方法名及参数
staticnew ()
staticnew_for_interval (min_value, max_value)
add_offset_value (name, value)
get_inverted ()
get_max_value ()
get_min_value ()
get_mode ()
get_offset_value (name)
get_value ()
remove_offset_value (name)
set_inverted (inverted)
set_max_value (value)
set_min_value (value)
set_mode (mode)
set_value (value)

Virtual Methods

do_offset_changed (name)

Properties

NameTypeFlagsShort Description
invertedboolr/w/enInvert the direction in which the level bar grows
max-valuefloatr/w/enMaximum value level that can be displayed by the bar
min-valuefloatr/w/enMinimum value level that can be displayed by the bar
modeGtk.LevelBarModer/w/enThe mode of the value indicator displayed by the bar
valuefloatr/w/enCurrently filled value level of the level bar

Signals

NameShort Description
offset-changedEmitted when an offset specified on the bar changes value as an effect to Gtk.LevelBar.add_offset_value() being called.

例子

这里写图片描述
代码:

#!/usr/bin/env python3
# Created by xiaosanyu at 16/7/14
# section 110
# 
# author: xiaosanyu
# website: yuxiaosan.tk \
#          http://blog.youkuaiyun.com/a87b01c14
# created: 16/7/14

TITLE = "LevelBar"
DESCRIPTION = """
The Gtk.LevelBar is a bar widget that can be used as a level indicator.
Typical use cases are displaying the strength of a password, or showing the charge level of a battery.

"""
import gi

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk, Gio, GLib


class LevelBarWindow(Gtk.Window):
    def __init__(self, *args, **kwargs):
        Gtk.Window.__init__(self, title="LevelBar Example")
        self.set_size_request(250, 200)
        box = Gtk.VBox(spacing=6)
        self.lb = Gtk.LevelBar(min_value=0, max_value=100, value=0, inverted=False, mode=Gtk.LevelBarMode.CONTINUOUS)

        box.pack_start(self.lb, False, False, 0)
        self.add(box)
        GLib.timeout_add(100, self.timeout)

    def timeout(self):
        max_value = self.lb.get_max_value()

        self.lb.set_value(self.lb.get_value() % max_value + 1)

        return True


def main():
    win = LevelBarWindow()
    win.connect("delete-event", Gtk.main_quit)
    win.show_all()
    Gtk.main()


if __name__ == "__main__":
    main()





代码下载地址: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、付费专栏及课程。

余额充值