我有一个小应用程序,使用a DrawingArea来绘制一个简单的地图使用PyGObject和GTK3.
我加载一个Pixbuf使用
from gi.repository import Gtk, GdkPixbuf
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size("logo.png", 25, 25)
Run Code Online (Sandbox Code Playgroud)
然后尝试在DrawingArea绘制事件信号中绘制它
def draw(self, widget, context):
window = widget.get_window()
ctx = window.cairo_create()
ctx.set_source_pixbuf(pixbuf, 0, 0)
Run Code Online (Sandbox Code Playgroud)
但我收到错误信息
"AttributeError: 'cairo.Context' object has no attribute 'set_source_pixbuf'"
Run Code Online (Sandbox Code Playgroud)
如果我正确阅读Gtk2到Gtk3迁移指南,这应该可行.我究竟做错了什么?