0

I am a beginner to using Glade and PyGTK and I am trying to create a window with a custom title bar that is created using the header bar component and the rest of the UI being done through a GLADE file. However instead of getting one window I am getting two different windows, one containing the header bar and the other containing the UI components developed in Glade. Could someone point me as to how to make them appear in the same window. PFB the code that has been written so far :

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


class HeaderBarWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="MLPP")
        self.set_border_width(10)
        self.set_default_size(400, 200)

        hb = Gtk.HeaderBar()
        hb.set_show_close_button(True)
        hb.props.title = "MLPP"
        self.set_titlebar(hb)

        titleBarImage = Gtk.Image() 
        titleBarImage.set_from_file('TitleIcon.png') 
        hb.pack_start(titleBarImage);   

        gladefile = "MLPP.glade"
        builder = Gtk.Builder()
        builder.add_from_file(gladefile)
        self.add(builder.get_object("window1"))



win = HeaderBarWindow()

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

1 Answers1

1
    builder.add_from_file(gladefile)
    self.add(builder.get_object("window1"))

Here you seem to get a "window" and add that to your intial Window. I guess you don't want to add the window defined in the Glade file, but one of its children. You probably have a Box or some other container defined. Try to get_object(box1) or however you identify your widget of desire.

Frederick Nord
  • 1,246
  • 1
  • 14
  • 31