简体   繁体   English

为什么Python.exe停止响应?

[英]Why Does Python.exe Stop Responding?

Why and when does Python.exe stop responding? 为什么以及何时Python.exe停止响应?

Today I was playing around with python/pygames, and making a sine/cosine wave graph. 今天,我在玩python / pygames,并制作了一个正弦/余弦波形图。 While trying to display the X-Position (int xPos), I used this statement: 尝试显示X位置(int xPos)时,我使用了以下语句:

    while xPos < WINDOW_WIDTH:
        stats1 = FONT1.render('X-Position: ' + str(xPos), True, BLACK, BACKGROUND_COLOR)
        stats1Rect = stats1.get_rect()

        stats1Rect.left = 100
        stats1Rect.bottom = 100

        DISPLAY.blit(stats1, stats1Rect)

Note: Constants BLACK, BACKGROUND_COLOR, etc. are all predefined. 注意:常量BLACK,BACKGROUND_COLOR等都是预定义的。 The while statement is in the main application loop while语句在主应用程序循环中

The 'xPos' integer is tracked and added to as the graph moves, and I want to constantly update the xPos integer to display where the graph is at on the x-axis. “ xPos”整数随图形移动而被跟踪并添加到其中,我想不断更新xPos整数以显示图形在x轴上的位置。

So, when I run the program, it is black and stops responding. 因此,当我运行该程序时,它是黑色的,并且停止响应。 Without the while statement, everything works as usual, with no errors. 没有while语句,一切都照常运行,没有错误。 I was wondering what maybe caused this and if there was a solution, whether it be placement of code or a different way of displaying. 我想知道是什么原因导致的,是否有解决方案,无论是代码放置还是其他显示方式。

When you increment xpos, an integer variable, you are trying to increment it by a float value. 当增加整数变量xpos时,您尝试将其增加浮点值。 Therefore you are comparing two different types, the value of xpos is never incremented, so the loop is infinite causing a runtime error. 因此,您正在比较两种不同的类型,xpos的值永远不会增加,因此循环是无限的,从而导致运行时错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM