Skip to main content
 首页 » 编程设计

python之为什么我们要在 button_press_event.handler 的最后返回 True

2025年05月04日11zhoujg

查看本页底部的示例: http://www.pygtk.org/pygtk2tutorial/sec-EventHandling.html 它说:

   57   def button_press_event(widget, event): 
   58       if event.button == 1 and pixmap != None: 
   59           draw_brush(widget, event.x, event.y) 
   60       return True 

那么,为什么会有“return True”呢?

请您参考如下方法:

您应该阅读您链接到的同一教程的介绍性章节。例如,chapter 2.3描述事件并说明返回值是什么。

The value returned from this function indicates whether the event should be propagated further by the GTK+ event handling mechanism. Returning True indicates that the event has been handled, and that it should not propagate further. Returning False continues the normal event handling. See Chapter 20, Advanced Event and Signal Handling for more details on this propagation process.