Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to show a png image in Gtk3 with Python?
    text
    copied!<p>First of all, it is important to mention that I'm learning <strong>Python</strong> and <strong>Gtk+ 3</strong>, so I'm not an advanced programmer in these languages.</p> <p>I'm trying to make a graphical interface in Gtk3 for a Python script that creates a <strong>png</strong> image, and I'd like to display it, but the <strong>PyGobject</strong> documentation is so scarce that I haven't found a way to do that. So far, my interface looks like this:</p> <p><img src="https://i.stack.imgur.com/j7e32.png" alt="enter image description here"></p> <p>The buttons and text entries are arranged in a grid, and I'd like to keep empty the big space (represented by the big button) to the right until the script finishes building the image, and then show it in that area. The code is <a href="https://dl.dropbox.com/u/10411539/makeRGB.py" rel="nofollow noreferrer">here</a>.</p> <p>Is there a way to do that using Python in Gtk3?</p> <p>Thanks in advance,</p> <p>Germán.</p> <h2>EDIT</h2> <p>Taking a look at the demos pointed out by @gpoo I discovered the <strong>Frame</strong> widget, and I implemented it in my GUI. This is how it looks like:</p> <p><img src="https://i.stack.imgur.com/xKNHX.png" alt="enter image description here"></p> <p>Inside the window class, I add the Frame to the grid:</p> <pre><code>self.frame_rgb = Gtk.Frame(label='RGB image') self.frame_rgb.set_label_align(0.5, 0.5) self.frame_rgb.set_shadow_type(Gtk.ShadowType.IN) self.grid.attach_next_to(self.frame_rgb, self.label_img_name, Gtk.PositionType.RIGHT, 3, 8) </code></pre> <p>I also connect the Run button to a callback function, so that when I click on it, my script creates and then displays the png image:</p> <pre><code>self.button_run = Gtk.Button(stock=Gtk.STOCK_EXECUTE) self.button_run.connect('clicked', self.on_button_run_clicked) self.grid.attach_next_to(self.button_run, self.entry_b_img, Gtk.PositionType.BOTTOM, 1, 1) </code></pre> <p>Finally, my callback function is (no calculations yet, only render the image to the Frame for testing purposes):</p> <pre><code>def on_button_run_clicked(self, widget): self.img = Gtk.Image.new_from_file('astro-tux.png') self.frame_rgb.add(self.img) </code></pre> <p>but I got the following error when I click the Run button:</p> <blockquote> <p>(makeRGB.py:2613): Gtk-WARNING **: Attempting to add a widget with type GtkImage to a GtkFrame, but as a GtkBin subclass a GtkFrame can only contain one widget at a time; it already contains a widget of type GtkImage</p> </blockquote> <p>Any help is appreciated!</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