【问题标题】:Have a popup window stay centered on parent - Glade, GTK, Python有一个以父级为中心的弹出窗口 - Glade、GTK、Python
【发布时间】:2017-06-18 16:05:06
【问题描述】:

谁能告诉我,即使在移动父窗口时,我如何才能让首选项弹出窗口保持在父窗口的中心?谢谢你:)

【问题讨论】:

    标签: python linux gtk glade


    【解决方案1】:

    这是一个非常简单的例子,首选项窗口居中,移动时父级也会移动(但取决于窗口管理器):

    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()
    

    导致:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多