PyGTK一次移动两个窗口

时间:2012-03-30 21:58:25

标签: python windows gtk pygtk glade

我正在使用Python 2.7与相应版本的PyGTK和GTK。 (>>> import gtk>>> gtk.pygtk_version(2,24,0)>>> gtk.gtk_version(2,24,8))我正在编写一个应用程序主窗口和可选的(根据切换按钮的状态)旁边还有一个设置窗口。

我试图一次移动两个窗口(使设置窗口STICK到主窗口,用主窗口移动它)。它默认在我的朋友MacBook上工作(我没有努力),但在我的Windows 7机器上却没有。我找到了一个解决方法,在主窗口移动完成后,设置窗口跳转到主窗口 - 但这不是我的目标。

编辑:仅供参考,“settings_window”有父“main_window”(我猜?)为Mac OS做正确的工作。

任何想法将不胜感激。 Thx,Erthy

1 个答案:

答案 0 :(得分:2)

此示例有效(在Ubuntu上):

#!/usr/bin/env python
#coding:utf8   
""" 
This PyGtk example shows two windows, the master and his dog. 
After master window moves or changes size, the dog window moves to always stay at its right border. 
This example should also account for variable thickness of the window border.
Public domain, Filip Dominec, 2012
"""

import sys, gtk

class Main: 
    def __init__(self):
        self.window1 = gtk.Window(); self.window1.set_title("Master")
        self.window2 = gtk.Window(); self.window2.set_title("Dog")

        self.window1.connect('configure_event', self.on_window1_configure_event) # move master -> move dog
        self.window1.connect('destroy', lambda w: gtk.main_quit()) # close master -> end program

        self.window1.show_all()
        self.window2.show_all()

    def on_window1_configure_event(self, *args):
        print "Window 1 moved!"
        x, y   = self.window1.get_position()
        sx, sy = self.window1.get_size()
        tx = self.window1.get_style().xthickness
        self.window2.move(x+sx+2*tx,y)

MainInstance = Main()       
gtk.main()                 
相关问题