2
我想暂停我的python脚本,而我等待用户按enter键 - 焦点位于matplotlib图上。暂停python并等待Matplotlib事件
我试过下面的代码,但脚本在进入wile循环时绑定事件处理。使其成为用户无法绘制矩形。
class DrawRectangle:
def __init__(self, image):
self.waiting_for_entry = True
'''
Event handling that lets user draw a rectangle on an image.
when the user is done drawing they press "enter" to disconnect the canvas
'''
def on_key_press(self, event):
if event.key == 'enter':
'''
disconnect event handling
'''
self.waiting_for_entry = False
def return_image_inside(self):
'''
Return the portion of the image inclosed in the rectangle
'''
if __name__ == "__main__":
image = import_some_image() # import an image
image_plot = plt.imshow(image)
selector = DrawRectangle(image_plot)
while selector.waiting_for_entry:
pass
working_data = selector.return_image_inside()
'''
do stuff with selected image
'''
的东西暂停程序一样
print "press enter to continue:"
raw_input()
的工作,但需要用户焦点返回到终端屏幕上,然后按Enter。
有关如何暂停脚本,直到事件在matplotlib中注册的任何建议?