简体   繁体   中英

Why Does Python.exe Stop Responding?

Why and when does Python.exe stop responding?

Today I was playing around with python/pygames, and making a sine/cosine wave graph. While trying to display the X-Position (int xPos), I used this statement:

    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. The while statement is in the main application loop

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.

So, when I run the program, it is black and stops responding. Without the while statement, everything works as usual, with no errors. 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. Therefore you are comparing two different types, the value of xpos is never incremented, so the loop is infinite causing a runtime error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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