pygame.event.wait()
今天要跟大家介紹Pygame event 模組裡的函式pygame.event.wait()
以下是官方文件的介紹
wait for a single event from the queue
wait() -> EventType instance
description
Returns a single event from the queue. If the queue is empty this function will wait until one is created. The event is removed from the queue once it has been returned. While the program is waiting it will sleep in an idle state. This is important for programs that want to share the system with other applications.
caution
This function should only be called in the thread that initialized
描述
等待並從佇列中獲取一個事件
wait() -> EventType instance
從佇列中返回並刪除一個事件。如果佇列為空,那麼該函式將持續等待直至佇列中有一個事件。當程式在等待時,它將保持睡眠狀態。這對於希望與其他應用程式共享系統來說,是非常重要的。
實例
def manual(self):
"""Take images manualy by pressing a key.(通過按鍵手動拍攝圖像)"""
while True:
#持續等待直至佇列中有一個事件
event = pygame.event.wait()
if event.type == QUIT:
break
#未點擊按鍵持續循環迴圈,直到點擊按鍵即手動拍攝圖像
if event.type != KEYDOWN:
continue
self.take()