Frage

In the following program I have a button that spawns a popup. Simple enough. Now I connect the main window's delete-event to Gtk.main_quit() so that closing the main window closes the program.

Without that it will keep running until I kill the process (As evidenced by the occupied CLI prompt) The question then is: What happens to the popup window when I click it away?

Is the window itself automatically being destroyed at the delete-event or does it just hide itself and linger somewhere in memory until the program ends?

#!/usr/bin/python3
from gi.repository import Gtk

class MainWin(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        button = PopupButton()
        self.add(button)
        self.show_all();
        self.connect("delete-event", Gtk.main_quit)

class PopupButton(Gtk.Button):
    def __init__(self):
        Gtk.Button.__init__(self, label="Popup")
        self.connect("clicked", self.clicked)

    def clicked(self, widget):
        win = PopupWindow()
        win.set_transient_for(self.get_toplevel())
        win.show()

class PopupWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.add(Gtk.Label(label="Popups! Popups for everyone!"))
        self.show_all()

win = MainWin()
win.show()
Gtk.main()
War es hilfreich?

Lösung

The default response to the delete-event signal is to destroy the window. So, unless you're handling that signal, the popup window is destroyed.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top