PyGobject(七十三)Gtk.Widget之Gtk.SpinButton
2016-08-01 13:09
746 查看
GtkSpinButton
继承关系
Methods
Virtual Methods
Properties
Signals
例子
代码:
代码下载地址:http://download.csdn.net/detail/a87b01c14/9594728
继承关系
Methods
Virtual Methods
Properties
Signals
例子
Gtk.SpinButton
Gtk.SpinButton带有加减号的输入框,输入内容必须在给定的范围内继承关系
Gtk.SpinButton是Gtk.Entry的直接子类Methods
方法修饰词 | 方法名及参数 |
---|---|
static | new (adjustment, climb_rate, digits) |
static | new_with_range (min, max, step) |
configure (adjustment, climb_rate, digits) | |
get_adjustment () | |
get_digits () | |
get_increments () | |
get_numeric () | |
get_range () | |
get_snap_to_ticks () | |
get_update_policy () | |
get_value () | |
get_value_as_int () | |
get_wrap () | |
set_adjustment (adjustment) | |
set_digits (digits) | |
set_increments (step, page) | |
set_numeric (numeric) | |
set_range (min, max) | |
set_snap_to_ticks (snap_to_ticks) | |
set_update_policy (policy) | |
set_value (value) | |
set_wrap (wrap) | |
spin (direction, increment) | |
update () |
Virtual Methods
do_change_value (scroll) |
do_input (new_value) |
do_output () |
do_value_changed () |
do_wrapped () |
Properties
Name | Type | Flags | Short Description |
---|---|---|---|
adjustment | Gtk.Adjustment | r/w | The adjustment that holds the value of the spin button |
climb-rate | float | r/w/en | The acceleration rate when you hold down a button |
digits | int | r/w/en | The number of decimal places to display |
numeric | bool | r/w/en | Whether non-numeric characters should be ignored |
snap-to-ticks | bool | r/w/en | Whether erroneous values are automatically changed to a spin button’s nearest step increment |
update-policy | Gtk.SpinButtonUpdatePolicy | r/w/en | Whether the spin button should update always, or only when the value is legal |
value | float | r/w/en | Reads the current value, or sets a new value |
wrap | bool | r/w/en | Whether a spin button should wrap upon reaching its limits |
Signals
Name | Short Description |
---|---|
change-value | The ::change-value signal is a keybinding signal which gets emitted when the user initiates a value change. |
input | The ::input signal can be used to influence the conversion of the users input into a double value. |
output | The ::output signal can be used to change to formatting of the value that is displayed in the spin buttons entry. |
value-changed | The ::value-changed signal is emitted when the value represented by spinbutton changes. |
wrapped | The ::wrapped signal is emitted right after the spinbutton wraps from its maximum to minimum value or vice-versa. |
例子
代码:
#!/usr/bin/env python3 # Created by xiaosanyu at 16/6/14 # section 117 TITLE = "SpinButton" DESCRIPTION = """ A Gtk.SpinButton is an ideal way to allow the user to set the value of some attribute. Rather than having to directly type a number into a Gtk.Entry, Gtk.SpinButton allows the user to click on one of two arrows to increment or decrement the displayed value. """ import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk class SpinButtonWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="SpinButton Demo") self.set_border_width(10) hbox = Gtk.Box(spacing=6) self.add(hbox) # lower<value<upper-page_size # step_increment鼠标左键(或者键盘上下键)按下增加或减少的值.page_increment键盘PageDown或PageUp按下增加或减少的值 # 当鼠标右键按下时,直接显示最大值或者最小值 adjustment = Gtk.Adjustment(value=0, lower=0, upper=20, step_increment=1, page_increment=2, page_size=1) self.spinbutton = Gtk.SpinButton() self.spinbutton.set_adjustment(adjustment) self.spinbutton.connect("value-changed", self.change_value) hbox.pack_start(self.spinbutton, False, False, 0) check_numeric = Gtk.CheckButton("Numeric") check_numeric.connect("toggled", self.on_numeric_toggled) hbox.pack_start(check_numeric, False, False, 0) check_ifvalid = Gtk.CheckButton("If Valid") check_ifvalid.connect("toggled", self.on_ifvalid_toggled) hbox.pack_start(check_ifvalid, False, False, 0) # 如果勾选,只能输入数字,其它字符不能输入 def on_numeric_toggled(self, button): self.spinbutton.set_numeric(button.get_active()) # 如果勾选,只有合法的数值才会更新.输入不合法的数值,还是显示原来的数值. # 当不勾选时,输入不合法的数值,第一次显示upper-page_size,后面就显示输入的数值 def on_ifvalid_toggled(self, button): if button.get_active(): policy = Gtk.SpinButtonUpdatePolicy.IF_VALID else: policy = Gtk.SpinButtonUpdatePolicy.ALWAYS self.spinbutton.set_update_policy(policy) @staticmethod def change_value(widget): print("change_value", widget.get_value()) def main(): win = SpinButtonWindow() win.connect("delete-event", Gtk.main_quit) win.show_all() Gtk.main() if __name__ == "__main__": main()
代码下载地址:http://download.csdn.net/detail/a87b01c14/9594728
相关文章推荐
- PyGobject(七十二)Gtk.Widget之Gtk.SearchEntry
- PyGobject(七十四)Gtk.Widget之Gtk.Scale
- PyGobject(七十五)Gtk.Widget之Gtk.Scrollbar
- PyGobject(七十六)Gtk.Widget之Gtk.Spinner
- PyGobject(七十七)Gtk.Widget之Gtk.Switch
- PyGobject(六十一)Gtk.Widget
- PyGobject(六十三)Gtk.Widget之Gtk.AccelLabel
- PyGobject(六十四)Gtk.Widget之Gtk.Arrow
- PyGobject(六十五)Gtk.Widget之Gtk.Image
- PyGobject(六十六)Gtk.Widget之Gtk.Calendar
- PyGobject(六十七)Gtk.Widget之Gtk.CellView
- PyGobject(六十八)Gtk.Widget之Gtk.DrawingArea
- PyGobject(六十九)Gtk.Widget之Gtk.LevelBar
- PyGobject(七十)Gtk.Widget之Gtk.ProgressBar
- PyGobject(七十一)Gtk.Widget之Gtk.Entry
- PyGobject(七)布局容器之Button篇——Gtk.FontButton
- PyGobject(八十六)Gtk.Application
- GTK如何给Label和其他的widget设置字体?不是使用API函数哦
- PyGobject(八十七)Gtk.PrintOperation
- 关于GTK+ widget上显示中文字符有误的问题!