zoukankan      html  css  js  c++  java
  • PyGame学习笔记之壹

    新建窗口

    代码

    '''PyGame学习笔记之壹'''
    import pygame                                # 引入 PyGame 库
    pygame.init()                                # PyGame 库初始化
    screen = pygame.display.set_mode([640, 480]) # 新建窗口,大小为[640, 480]
    running = True                               # 初始化窗口运行变量,表示窗口是否需要继续运行
    while running:                               # 需要继续运行是运行
        for event in pygame.event.get():         # 枚举 PyGame 事件
            if event.type == pygame.QUIT:        # 如果需要退出
                running = False                  # 窗口不需要继续运行
    pygame.quit()                                # PyGame 窗口退出
    

    分析

    pygame库运行前需要使用

    pygame.init()
    

    初始化一下,用于初始化 PyGame

    接着新建窗口screen,大小为[640, 480]

    screen = pygame.display.set_mode([640, 480])
    

    然后进入窗口主循环

    while running:
    

    为了能捕获到退出消息,还有进入事件循环

    for event in pygame.event.get():
    

    一旦发现捕获到了退出事件

    if event.type == pygame.QUIT:
    

    就将窗口运行变量running设为False,退出窗口主循环

    最后退出 PyGame 窗口

    参考文献

    1. 《父与子的编程之旅》 $ ext{P184 16.2 PyGame}$ 窗口
  • 相关阅读:
    Lucky Substrings
    KMP
    圆桌问题(hdu4841)
    codeforces 624C Graph and String
    Joseph(hdu1443)
    The Longest Straight(FZUoj2216)
    C1. 组队活动 Small(BNUOJ)
    A1. 道路修建 Small(BNUOJ)
    Problem 2221 RunningMan(fuzoj)
    CODEFORCEs 621E. Wet Shark and Blocks
  • 原文地址:https://www.cnblogs.com/XZDXRZ/p/12380287.html
Copyright © 2011-2022 走看看