pyGTK_读书笔记_Tutorial Chapter 5&6_Widget Overview and Button Widget
来源:互联网 发布:淘宝客源码免费下载 编辑:程序博客网 时间:2024/05/29 17:09
在pyGTK中使用部件的通用步骤:
1, 利用gtk.*创建一个部件对象;
2, 将我们需要使用的signal和event关联到相应的handler;
3, 配置部件的属性;
4, 调用gtk.Container.add()或者gtk.Box.pack_start()将部件包入容器;
5, 调用gtk.Widget.Show()保证在窗口上显示部件。
Buttion Widget: Normal Button;Toggle Button;Check Button;Radio Button
1, Normal Button
创建:button = gtk.Button(label=None, stock=None)
label: 定义按钮上的显示的文字;
stock: 将按钮的显示关联到库中的图标和文本。
Normal Button部件有如下的signal: pressed; released; clicked; enter; leave.
2, Toggle Button
Toggle Button有两种状态,点击一次,会呈现按下的状态;再次点击,则弹起。
创建:toggle_button = gtk.ToggleButton(label=None)
实例:
vbox = gtk.VBox(True, 2)
self.window.add(vbox)
button = gtk.ToggleButton("toggle button 1")# Create first button
button.connect("toggled", self.callback, "toggle button 1") # When the button is toggled, we call the "callback" method with a pointer to "button" as its argument
vbox.pack_start(button, True, True, 2)
button.show()
button = gtk.ToggleButton("toggle button 2") # Create second button
button.connect("toggled", self.callback, "toggle button 2")
vbox.pack_start(button, True, True, 2)
button.show()
vbox.show()
状态获取: 调用get_active()可以获取toggle部件(包括radio button和check button)的状态。
def toggle_button_callback(widget, data):
if widget.get_active():
# If control reaches here, the toggle button is down
else:
# If control reaches here, the toggle button is up
状态设置: toggle_button.set_active(is_active)
is_active取值True或者False,来决定Toggle Button的状态是down或up。在创建Toggle Button时,初始默认状态为up,即false。
3, Check Button
创建: check_button = gtk.CheckButton(label=None)
实例:
vbox = gtk.VBox(True, 2)
self.window.add(vbox)
# Create first button
button = gtk.CheckButton("check button 1")
button.connect("toggled", self.callback, "check button 1")
vbox.pack_start(button, True, True, 2)
button.show()
# Create second button
button = gtk.CheckButton("check button 2")
button.connect("toggled", self.callback, "check button 2")
vbox.pack_start(button, True, True, 2)
button.show()
vbox.show()
4, Radio Button
Radio Button是以一组按钮的形式出现,其中只有一个处于选中的状态。
创建: radio_button = gtk.RadioButton(group=None, label=None)
注意: 创建一组radio button中的第一个时,group=None。
实例:
box2 = gtk.VBox(False, 10)
box2.set_border_width(10)
box2.show()
button = gtk.RadioButton(None, "radio button1")
button.connect("toggled", self.callback, "radio button 1")
box2.pack_start(button, True, True, 0)
button.show()
button = gtk.RadioButton(button, "radio button2")
button.connect("toggled", self.callback, "radio button 2")
button.set_active(True)
box2.pack_start(button, True, True, 0)
button.show()
- pyGTK_读书笔记_Tutorial Chapter 5&6_Widget Overview and Button Widget
- pyGTK_读书笔记_Tutorial Chapter 4_Packing Widgets
- _widget
- _Widget
- 常用的Android Widget组件学习①--Button and TextView
- TC++PL Chapter 6 读书笔记
- TC++PL Chapter 5 读书笔记
- C++ Template读书笔记(chapter 5)
- 《SICP》读书笔记--Chapter 3 Modularity, Objects and State
- Scala Cookbook读书笔记 Chapter 4.Classes and Properties 第一部分
- Scala Cookbook读书笔记 Chapter 4.Classes and Properties 第二部分
- Chapter 1. Overview .open inventer
- chapter 2 SYSTEM ARCHITECTURE OVERVIEW
- Chapter 4. User Services Overview
- Chapter 6:Inheritance and Composition
- CHAPTER 5 References and Scoping
- Stock overview and cost assignment - 6
- Stock overview and cost assignment - 5
- android重力感应
- 关于错误:java.net.BindException: Cannot assign requested address
- EMMA: a free Java code coverage tool
- Gis软件改怎么选择
- js控制,背景变暗,弹出层,create_bg和remove_bg用来控制背景,移除后背景不变暗
- pyGTK_读书笔记_Tutorial Chapter 5&6_Widget Overview and Button Widget
- Android_listview分页加载更多
- 十招教你从程序员转向企业家
- 查找目录中所有带中文字符的文件,并列出中文所在的行
- 获得本周所有日期
- 空间3点投影定位算法
- hibernate.properties
- Android开发常见错误及技巧
- mysql存储引擎:InnoDB和MyISAM的区别与优劣