简体   繁体   English

gtk3文件中的全窗口图像(python3)

[英]Gtk3 Image full window image from file (python3)

I need to find a way to load a image from file such that the image is actual size. 我需要找到一种从文件加载图像的方法,以使图像为实际大小。 I have read documentation [here][ https://lazka.github.io/pgi-docs/Gtk-3.0] and [here][ http://python-gtk-3-tutorial.readthedocs.org/en/latest/index.html] but the only way that seems to work is using the builder class to load a gui designed in glade. 我在[这里] [ https://lazka.github.io/pgi-docs/Gtk-3.0]和[这里] [ http://python-gtk-3-tutorial.readthedocs.org/en/latest /index.html],但似乎唯一可行的方法是使用builder类加载在glade中设计的gui。 However via code I came up with the following and this does not produce the desired result, image is clipped. 但是,通过代码,我提出了以下内容,但未产生所需的结果,因此图像被裁剪。

from gi.repository import Gtk

class MainWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title='GMouse 600')
        self.layout = Gtk.Layout.new(None,None)
        self.add(self.layout)
        self.background = Gtk.Image.new_from_file('./images/g600-thumb-buttons.jpg')
        self.layout.put(self.background, 0, 0)    

window = MainWindow()
window.connect('delete-event', Gtk.main_quit)
window.show_all()
Gtk.main()

I'm trying to find out how I can do this via code, in such a way that my image is filling the window. 我试图找出如何通过代码做到这一点,以使我的图像充满窗口。 Can someone please provide any suggestions or possible solutions that I can try. 有人可以提供我可以尝试的任何建议或可能的解决方案。

Note that the reason I wish to do this via code is when I use glade it does produce the desired result except when I try to add a grid layout on top of the image, or any other widget, it will not allow me. 请注意,我希望通过代码执行此操作的原因是,当我使用Glade时,它确实会产生所需的结果,除非当我尝试在图像或任何其他小部件的顶部添加网格布局时,它不允许我这样做。 Also coding it will give me a chance to better learn and my gui is rather small, very few widgets will be used. 同时进行编码也会使我有机会更好地学习,并且我的gui很小,将很少使用小部件。

It seems I have solved the problem with the following code using Gtk.Overlay 看来我已经使用Gtk.Overlay用以下代码解决了问题

from gi.repository import Gtk

class MainWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title='GMouse 600')
        self.overlay = Gtk.Overlay()
        self.add(self.overlay)
        self.background = Gtk.Image.new_from_file('./images/g600-thumb-buttons.jpg')
        self.overlay.add(self.background)
        self.grid = Gtk.Grid()
        self.button = Gtk.Button(label='Test')
        self.grid.add(self.button)
        self.overlay.add_overlay(self.grid)


window = MainWindow()
window.connect('delete-event', Gtk.main_quit)
window.show_all()
Gtk.main()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM