如何在 python 3.4 中使用 Gtk3 在背景图像上插入小部件?
How can I insert a widget on a background image using Gtk3 in python 3.4?
我正在学习 python,我正在尝试使用 Gkt3 在 python 3.4 中创建一个应用程序。
起初我实现了将图像设置为背景,但后来我尝试添加日历并收到此警告:"gtkwindow can only contain one widget at a time"
然后我在 google 中搜索了一个解决方案并在这个网站上阅读了这个:
GtkWindow can only contain one widget at a time
我在这个 post 中找到了一个非常有用的答案 :) 看来解决方案是打包小部件:
http://www.pygtk.org/pygtk2tutorial/ch-PackingWidgets.html
我试过先做一个HBox做背景,插入图片,再做一个HBox,插入日历,最后把第二个框插入第一个框,结果不尽如人意。
这是我的代码:
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()
结果是:
Result
如您所见,日历是在背景之前插入的,而不是在背景
上插入的
我希望我解释清楚我的问题,我希望有人能帮助我。
谢谢。
米格尔.
要将其插入背景之上,您需要使用 Gtk.Overlay
而不是 Gtk.HBox
。
我正在学习 python,我正在尝试使用 Gkt3 在 python 3.4 中创建一个应用程序。 起初我实现了将图像设置为背景,但后来我尝试添加日历并收到此警告:"gtkwindow can only contain one widget at a time" 然后我在 google 中搜索了一个解决方案并在这个网站上阅读了这个:
GtkWindow can only contain one widget at a time
我在这个 post 中找到了一个非常有用的答案 :) 看来解决方案是打包小部件:
http://www.pygtk.org/pygtk2tutorial/ch-PackingWidgets.html
我试过先做一个HBox做背景,插入图片,再做一个HBox,插入日历,最后把第二个框插入第一个框,结果不尽如人意。
这是我的代码:
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()
结果是:
Result
如您所见,日历是在背景之前插入的,而不是在背景
上插入的我希望我解释清楚我的问题,我希望有人能帮助我。 谢谢。 米格尔.
要将其插入背景之上,您需要使用 Gtk.Overlay
而不是 Gtk.HBox
。