簡體   English   中英

PyGTK一次移動兩個窗口

[英]PyGTK moving two windows at once

我正在使用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

這個例子有效(在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()                 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM