我有一个基本的python gtk程序来显示窗口的位置,是否有一种简单的方法可以在移动时更新它?
#!/usr/bin/python
import gtk
class app(gtk.Window):
def __init__(self):
super(app, self).__init__()
self.set_position(gtk.WIN_POS_CENTER)
self.set_title("Window Position Test")
self.set_decorated(True)
self.set_has_frame(False)
self.set_resizable(False)
self.set_default_size(320, 50)
self.connect("destroy", gtk.main_quit)
vbox = gtk.VBox(spacing=4)
hbox = gtk.HBox(spacing=4)
self.pos_label = gtk.Label()
vbox.add(self.pos_label)
self.add(vbox)
self.update_pos()
self.show_all()
def update_pos(self):
''' Get window position, display + log '''
pos = str( self.get_position() )
print( pos )
self.pos_label.set_label( pos )
app()
gtk.main()
答案 0 :(得分:0)
最后需要附加到“configure-event”:
#!/usr/bin/python
import gtk
class app(gtk.Window):
def __init__(self):
super(app, self).__init__()
self.set_position(gtk.WIN_POS_CENTER)
self.set_title("Window Position Test")
self.set_decorated(True)
self.set_has_frame(False)
self.set_resizable(False)
self.set_default_size(320, 50)
self.connect("destroy", gtk.main_quit)
vbox = gtk.VBox(spacing=4)
hbox = gtk.HBox(spacing=4)
self.pos_label = gtk.Label()
vbox.add(self.pos_label)
self.add(vbox)
self.update_pos()
self.show_all()
self.connect("configure-event", self.update_pos)
def update_pos(self, *args):
''' Get window position, display + log '''
pos = str( self.get_position() )
print( pos )
self.pos_label.set_label( pos )
app()
gtk.main()