1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] How to show a png image in Gtk3 with Python?

Discussão em 'Python' iniciado por Stack, Outubro 7, 2024.

  1. Stack

    Stack Membro Participativo

    First of all, it is important to mention that I'm learning Python and Gtk+ 3, so I'm not an advanced programmer in these languages.

    I'm trying to make a graphical interface in Gtk3 for a Python script that creates a png image, and I'd like to display it, but the PyGobject documentation is so scarce that I haven't found a way to do that. So far, my interface looks like this:

    [​IMG]

    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 here.

    Is there a way to do that using Python in Gtk3?

    Thanks in advance,

    Germán.

    EDIT


    Taking a look at the demos pointed out by @gpoo I discovered the Frame widget, and I implemented it in my GUI. This is how it looks like:

    [​IMG]

    Inside the window class, I add the Frame to the grid:

    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)


    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:

    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)


    Finally, my callback function is (no calculations yet, only render the image to the Frame for testing purposes):

    def on_button_run_clicked(self, widget):
    self.img = Gtk.Image.new_from_file('astro-tux.png')
    self.frame_rgb.add(self.img)


    but I got the following error when I click the Run button:


    (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

    Any help is appreciated!

    Continue reading...

Compartilhe esta Página