鱼C论坛

 找回密码
 立即注册
查看: 2497|回复: 1

pygame不出来图形,求大神指点

[复制链接]
发表于 2015-6-17 08:49:13 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 戴宇轩 于 2015-6-21 22:08 编辑
  1. import pygame
  2. from pygame .locals import *
  3. pygame.init()
  4. screen = pygame.display.set_mode((600,500))
  5. pygame .display.set_caption("Drowing rectanglres")
  6. pos_x = 300
  7. pos_y = 250
  8. vel_x = 2
  9. vel_y = 1
  10. while True:
  11.     for event in pygame.event.get():
  12.         if event.type in (QUIT,KEYDOWN):
  13.             sys.exit()

  14. screen.fill((0,0,200))

  15. #move the rectangle
  16. pos_x += vel_x
  17. pos_y += vel_y

  18. #keep rectangle on the screen
  19. if pos_x > 500 or pos_x <0:
  20.     vel_x = -vel_x
  21. if pos_y >400 or pos_y < 0:
  22.     vel_y = -vel_y


  23. #draw the rectangle
  24. color = 255,255,0
  25. width = 0 #solid fill
  26. pos = pos_x,pos_Y,100,100
  27. pygame.draw.rect(screen, color, pos, width)

  28. pygame.display.update()
复制代码




试了好多次都是黑屏T-T  
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2017-5-26 14:57:53 | 显示全部楼层
因为你的程序会在while中一直循环,应该把15行以下的代码缩进到while中~
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-2-16 12:31

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表