使用pygtk和Glade将pixbuf绘制到绘图区域上 [英] drawing a pixbuf onto a drawing area using pygtk and glade
问题描述
我正在尝试用python创建GTK应用程序,我可以在其中单击屏幕将绘制的图像绘制到屏幕上。我尝试执行此操作的方法是将图像加载到pixbuf文件中,然后将该pixbuf绘制到绘图区域上。
i'm trying to make a GTK application in python where I can just draw a loaded image onto the screen where I click on it. The way I am trying to do this is by loading the image into a pixbuf file, and then drawing that pixbuf onto a drawing area.
代码的主要行在这里:
def drawing_refresh(self, widget, event):
#clear the screen
widget.window.draw_rectangle(widget.get_style().white_gc, True, 0, 0, 400, 400)
for n in self.nodes:
widget.window.draw_pixbuf(widget.get_style().fg_gc[gtk.STATE_NORMAL],
self.node_image, 0, 0, 0, 0)
这应该只是将pixbuf绘制到左上角的图像上,但是除了白色图像外什么也没有显示。我已经通过将pixbuf放入gtk图像中进行了测试。我在这里做什么错了?
This should just draw the pixbuf onto the image in the top left corner, but nothing shows but the white image. I have tested that the pixbuf loads by putting it into a gtk image. What am I doing wrong here?
推荐答案
我发现我只需要获取函数即可使用<$调用另一个暴露事件c $ c> widget.queue_draw()在函数末尾。该函数在开始时仅被调用一次,并且此时没有可用的节点,因此未绘制任何内容。
I found out I just need to get the function to call another expose event with widget.queue_draw()
at the end of the function. The function was only being called once at the start, and there were no nodes available at this point so nothing was being drawn.
这篇关于使用pygtk和Glade将pixbuf绘制到绘图区域上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!