I am creating a simple GTK3 application. The main toplevel window has a search button which will display another toplevel gtk3 window. When I click the close button (near the titlebar) on the second gtk3 window it closes as expected. However, when I click on the search button again, the second toplevel window is not redrawn with all its widgets..instead it appears empty.
If on the other hand, I click the close button (gtk button seen at the bottom) it closes properly. And when reopned all the widgets can be seen.
Info: I created the UI using Glade.
The code is displayed below. However to get the UI files, you need to download the package. You can download them here
#! /usr/bin/env python
from gi.repository import Gtk
import os,sys
UI_FILE = "main.ui"
SECOND_UI_FILE = "second.ui"
class SampleApp:
def __init__(self):
self.builder = Gtk.Builder()
self.builder.add_from_file(UI_FILE)
self.builder.connect_signals(self)
self.builder2 = Gtk.Builder()
self.builder2.add_from_file(SECOND_UI_FILE)
self.builder2.connect_signals(self)
self.window = self.builder.get_object('window')
self.window.set_position(Gtk.WindowPosition.CENTER)
self.window.connect("destroy", self.destroy)
self.window.show_all()
self.search = self.builder.get_object('button1')
self.search.connect("clicked", self.search_clicked)
def destroy(self, window):
Gtk.main_quit()
def search_clicked(self, window):
self.secondwindow = self.builder2.get_object('window1')
self.secondwindow.show_all()
def main():
app = SampleApp()
Gtk.main()
if __name__ == "__main__":
main()
Main Window

Second Window - Toplevel

Second Window - Blank

Why does this happen and how do I solve this?