Re: I need a basic tutorial for GUI creation using Cambalache

Lawrence D’Oliveiro <[email protected]>
Newsgroups comp.lang.python
Organization A noiseless patient Spider
Message-ID <[email protected]>
On Wed, 12 Aug 2026 09:26:38 +0100, Chris Green wrote:

> I'm sort of aware that Cambalache creates an XML file that
> represents the GUI and that XML file has to be processed somehow (by
> GTKBuilder?) to make a running GUI program.

Yeah, it seems in GTK4 you no longer have public access to the
individual widget-creation calls. But you can embed the entire XML
describing your UI inside your program code, which is convenient for
small, simple programs.

Here’s an example snippet from my limited dabbling with GTK4 so far:

    ui = \
        (
            "<?xml version='1.0' encoding='utf-8'?>\n"
            "<interface>\n"
            "    <requires lib='gtk' version='4.0'/>\n"
            "    <object class='GtkWindow' id='main'>\n"
            "        <child>\n"
            "            <object class='GtkGLArea' id='draw'/>\n"
            "        </child>\n"
            "    </object>\n"
            "</interface>\n"
        )
    junk = XMLElementTree.fromstring(ui)
      # just to check it’s syntactically OK, because Gtk.Builder.new_from_string simply
      # returns a builder object with no contents instead of reporting errors.
    bld = Gtk.Builder.new_from_string(ui, -1) # don’t know why wrapper insists on length arg
    sys.stdout.write("objects = %s\n" % repr(bld.get_objects())) # debug
    wdw = bld.get_object("main")
    drw = bld.get_object("draw")

Yeah, I discovered that, if there was an error in your XML, you didn’t
get any error message (that I could find), the returned Builder object
simply ended up with nothing in it.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.