Why does my cpu max out when I run pygames?

Question:
I’m trying to run a pygame, but my CPU maxes out and doesn’t even use/open the other window. This is a blackjack game, and as far as I know the code is good and formatted correctly.
Repl link:
https://replit.com/@Chair-GamingGam/blackjack

code snippet

Runs fine for me. If you want to reduce CPU usage, there are two options

  • Do not use python, as it is known to be one of the slowest and inefficient languages
  • Compile your python code or use pypy
1 Like

Alright, I will try that, thanks.

2 Likes

Just asking, how to compile python scripts

2 Likes

The easiest way is probably:

  1. poetry add -D nuitka
  2. python -m nuitka --follow-imports main.py

Formatting usually has nothing to do with CPU usage…

The code runs ok, but it only says hello world. As already stated, the best would be to move to another language when the CPU is clogged. But if the CPU bar goes red shortly and then goes down, i would not bother.

1 Like

This tutorial on pygame explains that you need to setup the frames per second to control how fast that loop is going. Check it out at about 16 to 17 minutes in. Pygame in 90 Minutes - For Beginners - YouTube