How to set size of a Gtk Image in Python

梦想与她 提交于 2019-12-24 06:11:22

问题


How can I set the width and height of a GTK Image in Python 3.


回答1:


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

new_from_file_at_scale (filename, width, height, preserve_aspect_ratio)

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

Simple Example:

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)


来源:https://stackoverflow.com/questions/42800482/how-to-set-size-of-a-gtk-image-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!