2015-10-25 38 views
0

我一直在试图在Xubuntu 14.04上使用Python进行GUI编程,方法是遵循如下一些指南here。我想在我的GUI中有一个背景图像,并在其上有任何按钮。 I searched on stackoverflow and came across a person having a similar issue。他的解决方案奏效了,但网格填满了整个窗口,我无法再看到背景图像。我该如何解决?这里是我的代码:为valignhalign属性创建网格时和Gtk + 3栅格遮挡背景图像覆盖

#!/usr/bin/env python 
# -*- coding: utf-8 -*-: 


from gi.repository import Gtk #Here we are importing the GTK3 library to use in our program 

class mywindow(Gtk.Window): 
    def __init__(self): 
     #In the class's constructor, we have to call the constructor of the super class. In addition, we tell it to set 
     #the value of the property title to Media Manager v1.0 
     Gtk.Window.__init__(self, title="Media Manager v1.0") #Creates an Empty Window 

     #use an overlay for the background image 
     self.overlay = Gtk.Overlay() 
     self.add(self.overlay) 
     self.background = Gtk.Image.new_from_file('Background.jpg') 
     self.overlay.add(self.background) 

     self.grid = Gtk.Grid() 
     self.button1 = Gtk.Button(label="Hello") 
     self.button1.connect("clicked", self.on_button1_clicked) 
     self.grid.add(self.button1) 
     self.overlay.add_overlay(self.grid) 



     #Gtk.Window.set_default_size(self, 400,325) 
     Gtk.Window.set_position(self, Gtk.WindowPosition.CENTER) 




    def on_button1_clicked(self, button): 
     print "Hello" 


    def on_button2_clicked(self, button): 
     print "Exiting..." 




def main(): 
    window = mywindow() 

    #connect to the window's delete event to ensure that the application is terminated if we click on the x to close the window 
    window.connect("delete-event", Gtk.main_quit) 

    #Display the window 
    window.show_all() 

    #Finally, start the GTK+ processing loop which we quit when the winndow is closed. 
    Gtk.main() 
    return 0 

if __name__ == '__main__': 
    main() 

回答

0

传递值/或按钮。这些属性的默认值是Gtk.Align.FILL,这导致它们覆盖给予它们的所有空间。相反,请选择Gtk.Align.STARTGtk.Align.ENDGtk.Align.CENTER