第一期 Python 程式設計入門共學營作業任務二十二


Nov 07, 2019

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()

程式設計實作題

#第一期Python程式設計入門共學營






你可能感興趣的文章

JS 表單驗證

JS 表單驗證

 5.字串比較

5.字串比較

[FE201] SASS 自動化、結論

[FE201] SASS 自動化、結論






留言討論




表現不錯喔,繼續加油~

看起來這個圖片長寬是固定的 (385, 216),應該可以寫成一個常數變數(全部大寫命名的變數,然後重複使用),避免直接 hard code 數值,這樣若需要更改數字需要同時改好多個地方





2
2
2