Binding a signal in a custom widget class

Viewed 37

I'm trying to add a custom Gtk.ListBoxRow to a Gtk.ListBox. This custom row is defined in the CustomRow class in the following way:

class CustomRow(Gtk.ListBoxRow):
    def __init__(self, label):
        super().__init__()

        button = Gtk.Button(label='button')
        label = Gtk.Label(label=label)
        box = Gtk.Box()
        box.add(button)
        box.add(label)

        self.add(box)


class Main:
    def __init__(self):
        super().__init__()
        ...

        self.listbox = Gtk.ListBox()
        ...
        self.listbox.add(CustomRow('label'))

    def button_clicked(self):
        print('button clicked')


if __name__ == '__main__':
    main = Main()
    main.window.show_all()
    Gtk.main()

What I now want to do is have is have the button be bound to button_clicked function found in Main - this function will remove the row from the listbox. Issue is that I have no idea how to do this from another class.

0 Answers
Related