Miguelw
Miguelw

Reputation: 13

How can I insert a widget on a background image using Gtk3 in python 3.4?

I'm learning python and I'm trying to create an application in python 3.4 using Gkt3. At first I achieved to set an image as background, but then I tried to add a calendar and got this warning: "gtkwindow can only contain one widget at a time" Then I searched a solution in google and read this in this site:

GtkWindow can only contain one widget at a time

I found a very useful answer in this post :) It seems the solution is packing Widgets:

http://www.pygtk.org/pygtk2tutorial/ch-PackingWidgets.html

I tried to make a HBox for the background and insert the image, then make another HBox, insert the calendar and finally insert the second box into the first box but the result was not as expected.

Here's my code:

from gi.repository import Gtk

class Lotus(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title="Lotus")
        Fondo = Gtk.Image.new_from_file("C:\loto.png")
        Calendario = Gtk.Calendar()
        box2 = Gtk.HBox()
        box1 = Gtk.HBox()
        box1.pack_start(box2, False, False, 0)
        box1.pack_start(Fondo, False, False, 0)
        box2.pack_start(Calendario, False, False, 0)

        self.add(box1)

win = Lotus()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()

And the result is:

Result

As you can see, the calendar was inserted before the background instead of on the background

I hope I explain clearly my problem and I hope someone can help me. Thanks. Miguel.

Upvotes: 1

Views: 1112

Answers (1)

ptomato
ptomato

Reputation: 57870

To insert it on top of the background, you'll want to use a Gtk.Overlay instead of a Gtk.HBox.

Upvotes: 1

Related Questions