python手记(6)
来源:互联网 发布:java replaceall 空格 编辑:程序博客网 时间:2024/05/21 14:58
#!/usr/bin/env python# example table.pyimport pygtkpygtk.require("2.0")import gtkclass Table:# Our callback.# The data passed to this method is printed to stdoutdef callback(self, widget, data=None):print "Hello again - %s was pressed" % data# This callback quits the programdef delete_event(self, widget, event, data=None):gtk.main_quit()return Falsedef __init__(self):# Create a new window self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)# Set the window titleself.window.set_title("Table")# Set a handler for delete_event that immediately# exits GTK.self.window.connect("delete_event", self.delete_event)# Sets the border width of the window.self.window.set_border_width(20)# Create a 2x2 tabletable = gtk.Table(2, 2, True)# Put the table in the main windowself.window.add(table)# Create first buttonbutton = gtk.Button("button 1")# When the button is clicked, we call the "callback" method# with a pointer to "button 1" as its argumentbutton.connect("clicked", self.callback, "button 1")# Insert button 1 into the upper left quadrant of the tabletable.attach(button, 0, 1, 0, 1)button.show()# Create second buttonbutton = gtk.Button("button 2")# When the button is clicked, we call the "callback" method# with a pointer to "button 2" as its argumentbutton.connect("clicked", self.callback, "button 2")# Insert button 2 into the upper right quadrant of the tabletable.attach(button, 1, 2, 0, 1)button.show()# Create "Quit" buttonbutton = gtk.Button("Quit")# When the button is clicked, we call the main_quit function# and the program exitsbutton.connect("clicked", lambda w: gtk.main_quit())# Insert the quit button into the both lower quadrants of the tabletable.attach(button, 0, 2, 1, 2)button.show()table.show()self.window.show()def main(): gtk.main() return 0if __name__ == "__main__":Table()main()
本博客所有内容是原创,未经书面许可,严禁任何形式的转
http://blog.csdn.net/u010255642
pygtk表格
table = gtk.Table(rows=1, columns=1, homogeneous=False)
第一个参数是表格的行数,第二个是表格的列数,homogeneous表格的box的大小是否调整成最大的widget的大小。rows=2且colunms=2的表格如下:
0 1 2
0+----------+----------+
|
|
|
1+----------+----------+
|
|
|
2+----------+----------+
在表格中放置widget
table.attach(child, left_attach, right_attach, top_attach, bottom_attach,
xoptions=EXPAND|FILL, yoptions=EXPAND|FILL, xpadding=0, ypadding=0)
假设你要在一个2*2的表格中,在首行放置widget,则 left_attach = 0,right_attach = 2, top_attach = 0,bottom_attach = 1。x和y字义了放置的选项,可以使用or定义多选项:
FILL表示如果表格单元比widget大一点,widget 在单元中将填充整个房间
FILL表示如果表格单元比widget大一点,widget 在单元中将填充整个房间
SHRINK 表示如果表格widget被分配小些的空间,widgets在窗体的底部被放置和消失
EXPAND导致表格单元被扩展到表格的余下空间
set_row_spacing() 和set_col_spacing() 在特定的行或列中加空间
table.set_row_spacing(row, spacing)
table.set_col_spacing(column, spacing)
table.set_col_spacing(column, spacing)
在所有行列中设置加固定空间
table.set_row_spacings(spacing)
table.set_col_spacings(spacing)
此外,在win下关闭窗口要注意:
此外,在win下关闭窗口要注意:
1.关闭按钮的事件如下:
button.connect_object("clicked", gtk.Widget.destroy,window)
2.编写一个destroy的处理函数
def close_application(self, widget):
gtk.main_quit()
3.在__init__中设置处理窗口destroy的函数
window.connect("destroy", self.close_application)
我们将上面的代码修改后可以成功退出窗口
#!/usr/bin/env python# example table.pyimport pygtkpygtk.require("2.0")import gtkclass Table: # Our callback. # The data passed to this method is printed to stdout def callback(self, widget, data=None): print "Hello again - %s was pressed" % data # This callback quits the program def delete_event(self, widget, event, data=None): gtk.main_quit() return False def close_application(self, widget): gtk.main_quit() def __init__(self): # Create a new window self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) # Set the window title self.window.set_title("Table") # Set a handler for delete_event that immediately # exits GTK. self.window.connect("delete_event", self.delete_event) # Sets the border width of the window. self.window.set_border_width(20) # Create a 2x2 table table = gtk.Table(2, 2, True) # Put the table in the main window self.window.add(table) # Create first button button = gtk.Button("button 1") # When the button is clicked, we call the "callback" method # with a pointer to "button 1" as its argument button.connect("clicked", self.callback, "button 1") # Insert button 1 into the upper left quadrant of the table table.attach(button, 0, 1, 0, 1) button.show() # Create second button button = gtk.Button("button 2") # When the button is clicked, we call the "callback" method # with a pointer to "button 2" as its argument button.connect("clicked", self.callback, "button 2") # Insert button 2 into the upper right quadrant of the table table.attach(button, 1, 2, 0, 1) button.show() # Create "Quit" button button = gtk.Button("Quit") # When the button is clicked, we call the main_quit function # and the program exits button.connect_object("clicked", gtk.Widget.destroy,self.window) # Insert the quit button into the both lower quadrants of the table table.attach(button, 0, 2, 1, 2) self.window.connect("destroy", self.close_application) button.show() table.show() self.window.show() def main(): gtk.main() return 0if __name__ == "__main__": Table() main()
- python手记(6)
- Python 手记
- python手记
- python socket 编程手记
- Python重载学习手记
- python手记(1)
- python手记(2)
- python手记(3)
- python手记(4)
- python手记(5)
- python手记(7)
- python手记(8)
- python手记(9)
- python手记(10)
- python手记(11)
- python手记(12)
- python手记(14)
- python手记(15)
- 将表的字段(pid)属性改为AUTO_INCREMENT
- 快速揭开Word制表位设置的神秘面纱【系统收藏】
- linux kernel.shmall shemax shemin解释
- 2013年6月26 日我打开支付宝页面,向余额宝转入了 20元。
- ubuntu-arm 程序脚本自启动
- python手记(6)
- C++中覆盖、隐藏的区别
- LINQ to List泛型的几种简单查询(转:http://www.189works.com/article-43804-1.html)
- 0625学习笔记
- TCPserver客户端
- 共享中断 IRQF_SHARED 使用方法
- 【用户指南:Win8预设9种背景颜色随心切换】
- 四大实习时发现美女主管天天偷看这些网站,明白之后我也陷进去了~
- Android - ListView