开发者社区> 问答> 正文

pygame 程序未报错却黑屏无法显示 请问有大佬知道解决方法吗

pygame 程序未报错却黑屏无法显示 请问有大佬知道解决方法吗?

展开
收起
问问小秘 2020-01-02 11:43:48 1609 0
1 条回答
写回答
取消 提交回答
  • 以下是从一本书上抄下来稍加改动的源代码,在 Python Idle 里运行没有报错,然而弹出的 pygame 窗口却除了显示窗口标题外一片漆黑。(如下图)

    import pygame import sys

    set everything to where started

    pygame.init()

    size = width, height = 650, 650 speed = [-2,1] bg = (255, 255, 255)

    create a window with a determined size

    screen = pygame.display.set_mode(size)

    create window title

    pygame.display.set_caption("Hello!")

    ball = pygame.image.load("D://Python//soccer.jpg")

    position of the image

    position = ball.get_rect()

    while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit()

    move the image

    position = position.move(speed)

    if position.left < 0 or position.right > height: # flip image turtle = pygame.transform.flip(ball, True, False) # move to the other side speed[1] = -speed[1]

    if position.top < 0 or position.bottom > height: speed[1] = -speed[1]

    fill the background

    screen.fill()

    refresh image

    screen.blit(ball, position)

    refresh screen

    pygame.display.flip() pygame.display.update()

    10ms delay

    pygame.time.delay(10)

    2020-01-02 11:44:43
    赞同 展开评论 打赏
来源圈子
更多
收录在圈子:
+ 订阅
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载