pygtk-Fixed Container

固定容器 Fixed Container
固定容器(The Fixed container)允许将构件放在窗口的固定位置,这个位置是相对于固定容器的左上角的。构件的位置可以动态改变。

只有少数几个与固定容器构件相关的函数:

GtkWidget* gtk_fixed_new( void );

void gtk_fixed_put( GtkFixed *fixed,
GtkWidget *widget,
gint x,
gint y );

void gtk_fixed_move( GtkFixed *fixed,
GtkWidget *widget,
gint x,
gint y );

gtk_fixed_new() 函数用于创建新的固定容器。

gtk_fixed_put() 函数将widget放在fixed的由x和y指定的位置。

gtk_fixed_move() 函数将指定构件移动到新位置。


#!/usr/bin/env python

# example fixed.py

import pygtk
pygtk.require('2.0')
import gtk

class FixedExample:
# This callback method moves the button to a new position
# in the Fixed container.
def move_button(self, widget):
self.x = (self.x+30)%300
self.y = (self.y+50)%300
self.fixed.move(widget, self.x, self.y)

def __init__(self):
self.x = 50
self.y = 50

# Create a new window
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_title("Fixed Container")

# Here we connect the "destroy" event to a signal handler
window.connect("destroy", lambda w: gtk.main_quit())

# Sets the border width of the window.
window.set_border_width(10)

# Create a Fixed Container
self.fixed = gtk.Fixed()
window.add(self.fixed)
self.fixed.show()

for i in range(1, 4):
# Creates a new button with the label "Press me"
button = gtk.Button("Press me")

# When the button receives the "clicked" signal, it will call the
# method move_button().
button.connect("clicked", self.move_button)

# This packs the button into the fixed containers window.
self.fixed.put(button, i*50, i*50)

# The final step is to display this newly created widget.
button.show()

# Display the window
window.show()
def main():
# Enter the event loop
gtk.main()
return 0

if __name__ == "__main__":
FixedExample()
main()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值