我尝试使用一个非常简单的代码来创建一个使用python 3.6.1的矩形形状。我不确定我使用的代码是否会导致程序在每次使用时崩溃,或者是否有人可以给我提供pygame模块,我的cmd和我正在使用的代码之间可能发生的情况的建议。 Python 3.6 pygame崩溃
0
A
回答
0
当我运行你的代码时,窗口加载并显示矩形,但是,我认为你的问题涉及试图退出程序。要做到这一点,你需要有一个事件循环,将杀人游戏,当用户退出了游戏循环:
import pygame
pygame.init()
isrunning = True
window = pygame.display.set_mode((500, 400))
while isrunning:
for event in pygame.event.get():
if event.type == pygame.QUIT:
isrunning = False
pygame.draw.rect(window, (255, 0, 0), (0, 0, 50, 30)) #here, access the rect method
pygame.display.update()
0
您将需要一个背景颜色来填充屏幕。如果你想黑色,你仍然需要手动设置背景颜色为黑色。
import pygame
pygame.init()
window = pygame.display.set_mode((500, 400))
while True:
window.fill(0, 0, 0)
pygame.draw.rect(window, (255, 0, 0), (0, 0, 50, 30))
pygame.display.flip()
如果添加帧频并添加事件循环,会更好。
import pygame
pygame.init()
window = pygame.display.set_mode((500, 400))
clock = pygame.time.Clock()
while True:
window.fill(0, 0, 0)
pygame.event.pump() # use pump if you’re not planning to catch any event
pygame.draw.rect(window, (255, 0, 0), (0, 0, 50, 30))
pygame.display.flip()
clock.tick(50) # add the frame rate, should always be > 30
而作为一般的提示,使用flip()
如果你没有传递任何矩形参数update()
0
import pygame
pygame.init()
window = pygame.display.set_mode((500, 400))
while True:
pygame.draw.rect(window, (255,0,0),
(0, 0, 50, 30))
pygame.display.update()
继承人的代码
+0
单击编辑按钮编辑您的帖子,不要发布非回答作为答案,但非常适合您粘贴您的代码。请删除这个答案。 – abccd
相关问题
- 1. pygame的龟崩溃
- 2. Pygame崩溃
- 3. Pygame版本与python 3.6
- 4. 程序不断崩溃(Python + pygame
- 5. Python的崩溃上装载pygame的
- 6. 如何在python 3.6上安装pygame?
- 7. pygame声音文件崩溃IDLE
- 8. Python 3.6 - Sanic Motorengine
- 9. PyQtGraph崩溃python
- 10. Spynner崩溃python
- 11. Python pygame崩溃,修复似乎并不工作
- 12. 调试Python崩溃
- 13. Python与SFrame崩溃
- 14. Python程序崩溃
- 15. pygame在采取行动后立即崩溃
- 16. 在OSX崩溃的wx python
- 17. tensorflow执行python崩溃
- 18. 痛饮崩溃的Python
- 19. Numba崩溃与Python 3.3 64
- 20. 如何记录Python崩溃?
- 21. Django注销()崩溃Python
- 22. Python导入pyqt时崩溃
- 23. 的Python崩溃导入
- 24. Python是否应该崩溃?
- 25. Python中的崩溃报告
- 26. 调用CreateProcessWithLogonW后Python崩溃
- 27. Firefox 3.6的崩溃试图显示缩略图
- 28. 试图在Selenium中设置pageloadtimeout时崩溃3.6
- 29. 使用填充(颜色)方法时,pygame崩溃
- 30. 的Python - 创建有意义的崩溃日志/崩溃报告
@Alastair假,pygame中要求用户有和无限''while'循环来模拟连续事件循环 – abccd
@jayardot,尽管代码非常简单,但我们希望您将代码复制并粘贴到问题本身(以避免误读,并防止托管的风险现场采取行动图像)。 – abccd
什么崩溃?你为什么认为这里发生了崩溃? – user2357112