如何在Python中设置Gtk图像的大小 [英] How to set size of a Gtk Image in Python

查看:130
本文介绍了如何在Python中设置Gtk图像的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Python 3 中设置 GTK图像宽度高度.

推荐答案

首先使用 new_from_file_at_scale 创建一个 GdkPixbuf strong>方法具有以下语法.

First create a GdkPixbuf with the new_from_file_at_scale method which has the following syntax.

new_from_file_at_scale(文件名,宽度,高度,preserve_aspect_ratio)

使用方法 new_from_pixbuf 创建小部件 Gtk.Image ,该小部件将接收 pixbuf 作为参数.

Create the widget Gtk.Image with the method new_from_pixbuf which receives a pixbuf as parameter.

简单示例:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GdkPixbuf

pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
        filename="1.jpg", 
        width=24, 
        height=24, 
        preserve_aspect_ratio=True)

image = Gtk.Image.new_from_pixbuf(pixbuf)

这篇关于如何在Python中设置Gtk图像的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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