Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Let's say you have this ui file</p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!-- Generated with glade 3.15.3 on Tue Sep 17 10:11:35 2013 --&gt; &lt;interface&gt; &lt;!-- interface-requires gtk+ 3.10 --&gt; &lt;object class="GtkGrid" id="grid2"&gt; &lt;property name="visible"&gt;True&lt;/property&gt; &lt;property name="row_spacing"&gt;12&lt;/property&gt; &lt;property name="row_homogeneous"&gt;True&lt;/property&gt; &lt;child&gt; &lt;object class="GtkLabel" id="label1"&gt; &lt;property name="visible"&gt;True&lt;/property&gt; &lt;property name="label" translatable="yes"&gt;I'm a widget from the new content&lt;/property&gt; &lt;/object&gt; &lt;packing&gt; &lt;property name="left_attach"&gt;0&lt;/property&gt; &lt;property name="top_attach"&gt;0&lt;/property&gt; &lt;property name="width"&gt;1&lt;/property&gt; &lt;property name="height"&gt;1&lt;/property&gt; &lt;/packing&gt; &lt;/child&gt; &lt;child&gt; &lt;object class="GtkLabel" id="label2"&gt; &lt;property name="visible"&gt;True&lt;/property&gt; &lt;property name="label" translatable="yes"&gt;Me too&lt;/property&gt; &lt;/object&gt; &lt;packing&gt; &lt;property name="left_attach"&gt;0&lt;/property&gt; &lt;property name="top_attach"&gt;1&lt;/property&gt; &lt;property name="width"&gt;1&lt;/property&gt; &lt;property name="height"&gt;1&lt;/property&gt; &lt;/packing&gt; &lt;/child&gt; &lt;/object&gt; &lt;object class="GtkWindow" id="window1"&gt; &lt;child&gt; &lt;object class="GtkGrid" id="grid1"&gt; &lt;property name="visible"&gt;True&lt;/property&gt; &lt;child&gt; &lt;object class="GtkButton" id="button1"&gt; &lt;property name="label" translatable="yes"&gt;button&lt;/property&gt; &lt;property name="visible"&gt;True&lt;/property&gt; &lt;/object&gt; &lt;packing&gt; &lt;property name="left_attach"&gt;0&lt;/property&gt; &lt;property name="top_attach"&gt;0&lt;/property&gt; &lt;property name="width"&gt;1&lt;/property&gt; &lt;property name="height"&gt;1&lt;/property&gt; &lt;/packing&gt; &lt;/child&gt; &lt;child&gt; &lt;object class="GtkButton" id="button2"&gt; &lt;property name="label" translatable="yes"&gt;button&lt;/property&gt; &lt;property name="visible"&gt;True&lt;/property&gt; &lt;/object&gt; &lt;packing&gt; &lt;property name="left_attach"&gt;1&lt;/property&gt; &lt;property name="top_attach"&gt;1&lt;/property&gt; &lt;property name="width"&gt;1&lt;/property&gt; &lt;property name="height"&gt;1&lt;/property&gt; &lt;/packing&gt; &lt;/child&gt; &lt;child&gt; &lt;object class="GtkButton" id="button3"&gt; &lt;property name="label" translatable="yes"&gt;button&lt;/property&gt; &lt;property name="visible"&gt;True&lt;/property&gt; &lt;/object&gt; &lt;packing&gt; &lt;property name="left_attach"&gt;2&lt;/property&gt; &lt;property name="top_attach"&gt;2&lt;/property&gt; &lt;property name="width"&gt;1&lt;/property&gt; &lt;property name="height"&gt;1&lt;/property&gt; &lt;/packing&gt; &lt;/child&gt; &lt;/object&gt; &lt;/child&gt; &lt;/object&gt; &lt;/interface&gt; </code></pre> <p>Now, you create you your window as usual:</p> <pre><code> window1 = self.builder.get_object('window2') window1.show_all() </code></pre> <p>If you want to change the content of the window. Then you need to destroy/hide the widget you want to hide.</p> <pre><code> grid1 = self.builder.get_object('grid1') grid1.destroy() grid2 = self.builder.get_object('grid2') window1.add (grid2) </code></pre> <p>And we're all good to go. You can load your second widget hierarchy (<em>grid2</em>, I mean) from the same initial ui file or from a new one. What you need to understand, is that after the <strong>Builder</strong> create the objects from the ui files, it can't modify those further.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload