gtk3文件中的全窗口图像(python3) [英] Gtk3 Image full window image from file (python3)

查看:161
本文介绍了gtk3文件中的全窗口图像(python3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找到一种从文件加载图像的方法,以使图像为实际大小.我已经阅读了文档[此处] [ https://lazka.github.io/pgi -docs/Gtk-3.0] 和[here] [

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

请注意,我希望通过代码执行此操作的原因是,当我使用林间空地时,它确实会产生所需的结果,除非当我尝试在图像或任何其他小部件上添加网格布局时,它不允许我这样做.另外,通过编码,我将有机会更好地学习,并且gui很小,将使用很少的小部件.

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. Also coding it will give me a chance to better learn and my gui is rather small, very few widgets will be used.

推荐答案

似乎我已经使用Gtk.Overlay使用以下代码解决了问题

It seems I have solved the problem with the following code using 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()

这篇关于gtk3文件中的全窗口图像(python3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆