2017-06-18 81 views

回答

3

這是一個很簡單的例子,優先窗口爲中心,而移動它的母公司將移動(但將取決於窗口管理器):

import gi 
gi.require_version('Gtk', '3.0') 
from gi.repository import Gtk 

class AppWindow(Gtk.Window): 

    def __init__(self): 
     Gtk.Window.__init__(self, title="Python Example") 

     box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,spacing=6) 
     self.add(box) 

     button1 = Gtk.Button("Information") 
     button1.connect("clicked", self.on_button_clicked) 
     box.add(button1) 

     treeview = Gtk.TreeView() 
     treeview.set_size_request(640,480) 
     box.add(treeview) 

    def on_button_clicked(self, widget): 
     preferences_window = Gtk.Window (Gtk.WindowType.TOPLEVEL) 
     preferences_window.set_title ("Preferences Window") 
     preferences_window.set_modal (True) 
     preferences_window.set_position(Gtk.WindowPosition.CENTER_ON_PARENT) 
     preferences_window.set_transient_for(self) 
     preferences_window.show_all() 
     preferences_window.connect("delete-event", preferences_window.destroy); 

win = AppWindow() 
win.connect("delete-event", Gtk.main_quit) 
win.show_all() 
Gtk.main() 

,導致: enter image description here