This is a simple tool created in a minute with artificial intelligence to help me create sprites with a blend effect based on a map for ffmpeg. I used Python version 3.13.0, pyqt6, pygame, ...
Python tutorials with source code, examples, guides, and tips and tricks for Windows and Linux development.
Showing posts with label pygame. Show all posts
Showing posts with label pygame. Show all posts
Tuesday, April 21, 2026
Python Qt : sprites tool idea with ffmpeg.
Posted by
Cătălin George Feștilă
Labels:
2026,
2D,
module,
modules,
packages,
programming,
pygame,
PyQt6,
python,
python modules,
python packages,
python3,
tutorial,
tutorials
Monday, April 13, 2026
Python 3.13.0 : bypasses pygame‑ce and use directly to Windows with ctypes.
Today, I test bypasses pygame‑ce and use directly to Windows, because the Python 3.13 + pygame‑ce 2.5.7, where DPI functions are missing.
You can read more about this idea on my pygame blogger, see the blogger post.
Windows exposes thousands of functions through: user32.dll, gdi32.dll, shcore.dll, kernel32.dll, dwmapi.dll.
If the OS provides the feature → Python can call it via ctypes.
Python can call Windows API functions directly whenever the OS provides a stable API, and you only perform operations that are safe at the OS level.
These are always safe to do from Python using ctypes, because they only interact with the OS, not with internal memory of another library.
- Reading information
- DPI
- monitor list
- window position
- window size
- screen resolution
- system metrics
- OS version
- keyboard/mouse state
- window styles
- process info
- Calling OS-level functions that modify the window
- move window
- resize window
- change window title
- change window transparency
- change window z-order
- set DPI awareness
- toggle fullscreen
- minimize / maximize
- Creating new OS objects
- timers
- threads
- windows (if you want)
- file handles
- pipes
- events
- Using OS-level graphics
- GDI drawing
- DWM effects
- Aero shadow
- blur behind window
- Unsafe
- Writing into internal memory of SDL2, Python, or any DLL
- Overwriting function pointers
- Injecting hooks
- Modifying struct layouts
- Freeing memory you don’t own
This is just one part of source code:
import pygame
import pygame._sdl2 as sdl2
import ctypes
import sys
pygame.init()
# Windows DPI API
user32 = ctypes.windll.user32
shcore = ctypes.windll.shcore
# Enable per-monitor DPI awareness
try:
shcore.SetProcessDpiAwareness(2)
except:
pass
...
user32.EnumDisplayMonitors(0, 0, MonitorEnumProc(_monitor_enum_proc), 0)
...
Posted by
Cătălin George Feștilă
Labels:
2026,
ctypes,
pygame,
python,
python 3,
sys,
tutorial,
tutorials,
video tutorial
Friday, April 10, 2026
Python Qt : particles with pygame and pyqt6.
Today, I test one python script with pygame and pyqt6. The python script use classes and show particles. See the result:

This is the source code:
import sys
import random
import pygame
from pygame import Vector2
from PyQt6.QtWidgets import (
QApplication, QWidget, QVBoxLayout, QHBoxLayout,
QSlider, QLabel, QSizePolicy
)
from PyQt6.QtCore import Qt, QTimer
from PyQt6.QtGui import QImage, QPainter
class Particle:
def __init__(self, pos, vel, color):
self.pos = Vector2(pos)
self.vel = Vector2(vel)
self.color = color
self.life = 255
def update(self, gravity):
self.vel.y += gravity
self.pos += self.vel
self.life -= 2
def draw(self, surf):
if self.life > 0:
pygame.draw.circle(
surf,
self.color,
(int(self.pos.x), int(self.pos.y)),
4
)
class PygameWidget(QWidget):
def __init__(self):
super().__init__()
pygame.init()
pygame.display.init()
self.w, self.h = 900, 600
self.surface = pygame.Surface((self.w, self.h))
self.particles = []
self.spawn_rate = 5
self.gravity = 0.1
self.setSizePolicy(
QSizePolicy.Policy.Expanding,
QSizePolicy.Policy.Expanding
)
self.timer = QTimer()
self.timer.timeout.connect(self.game_loop)
self.timer.start(16) # ~60 FPS
def spawn_particles(self):
for _ in range(self.spawn_rate):
pos = (self.w // 2, self.h // 2)
vel = (random.uniform(-2, 2), random.uniform(-2, 2))
color = (255, random.randint(100, 255), 0)
self.particles.append(Particle(pos, vel, color))
def game_loop(self):
self.surface.fill((20, 20, 20))
self.spawn_particles()
alive = []
for p in self.particles:
p.update(self.gravity)
p.draw(self.surface)
if p.life > 0:
alive.append(p)
self.particles = alive
self.update()
def paintEvent(self, event):
data = pygame.image.tobytes(self.surface, "RGB")
img = QImage(
data,
self.w,
self.h,
self.w * 3,
QImage.Format.Format_RGB888
)
painter = QPainter(self)
painter.drawImage(0, 0, img)
painter.end()
def resizeEvent(self, event):
self.w = self.width()
self.h = self.height()
self.surface = pygame.Surface((self.w, self.h))
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("PyQt6 + pygame Particle System")
main_layout = QVBoxLayout()
# widget-ul pygame – ocupă tot spațiul
self.pg_widget = PygameWidget()
main_layout.addWidget(self.pg_widget, stretch=1)
# panou de controale jos
control_panel = QVBoxLayout()
# ----- slider spawn rate -----
spawn_layout = QHBoxLayout()
spawn_label = QLabel("Spawn:")
self.spawn_value = QLabel("5")
spawn_slider = QSlider(Qt.Orientation.Horizontal)
spawn_slider.setRange(1, 50)
spawn_slider.setValue(5)
spawn_slider.valueChanged.connect(self.update_spawn_rate)
spawn_layout.addWidget(spawn_label)
spawn_layout.addWidget(spawn_slider)
spawn_layout.addWidget(self.spawn_value)
# ----- slider gravity -----
gravity_layout = QHBoxLayout()
gravity_label = QLabel("Gravity:")
self.gravity_value = QLabel("0.10")
gravity_slider = QSlider(Qt.Orientation.Horizontal)
gravity_slider.setRange(0, 50)
gravity_slider.setValue(10)
gravity_slider.valueChanged.connect(self.update_gravity)
gravity_layout.addWidget(gravity_label)
gravity_layout.addWidget(gravity_slider)
gravity_layout.addWidget(self.gravity_value)
control_panel.addLayout(spawn_layout)
control_panel.addLayout(gravity_layout)
main_layout.addLayout(control_panel)
self.setLayout(main_layout)
def update_spawn_rate(self, v):
self.pg_widget.spawn_rate = v
self.spawn_value.setText(str(v))
def update_gravity(self, v):
g = v / 100.0
self.pg_widget.gravity = g
self.gravity_value.setText(f"{g:.2f}")
if __name__ == "__main__":
app = QApplication(sys.argv)
w = MainWindow()
w.resize(1000, 800)
w.show()
sys.exit(app.exec())
Posted by
Cătălin George Feștilă
Labels:
2026,
2D,
module,
modules,
packages,
programming,
pygame,
PyQt6,
python,
python modules,
python packages,
python3,
tutorial,
tutorials
Saturday, February 22, 2025
News : Python and Grok 3 Beta — The Age of Reasoning Agents
On the official website of x.ai you can find this:
We are thrilled to unveil an early preview of Grok 3, our most advanced model yet, blending superior reasoning with extensive pretraining knowledge.
You can find a simle and good example with python and pygame how this can be used.
The Grok 3 artificial inteligence is used for :
Research
Brainstorm
Analyze Data
Create images
Code
For me, the artificial intelligence help me to be more fast into coding versus issues and bugs, game design, parse and change data.
I don't test this Grok 3, but I can tell you some artificial inteligence into develop area are bad even they say is dedicated to this issue.
Posted by
Cătălin George Feștilă
Labels:
2025,
2025 news,
artificial intelligence,
grok 3,
news,
pygame,
python,
python 3
Saturday, September 21, 2024
Python 3.12.3 : 8in8 game project with pygame and agentpy - 001.
I started a game project with the python packages pygame and agentpy in the Fedora Linux distribution.
You can find it on my fedora pagure repo

Posted by
Cătălin George Feștilă
Labels:
2024,
agentpy,
fedora,
linux,
module,
modules,
packages,
pygame,
python,
python 3,
python modules,
python packages,
tutorial,
tutorials
Tuesday, September 17, 2024
Python 3.12.3 : PyGame, DuckDB and AgentPy on Fedora 42 linux distro.
Today I tested the installation of some python packages in the Fedora 42 Linux distribution. On the Windows 10 operating system I failed to install pygame because it was trying to build.
[mythcat@fedora ~]$ pip install duckdb --upgrade
Defaulting to user installation because normal site-packages is not writeable
Collecting duckdb
...
Installing collected packages: duckdb
Successfully installed duckdb-1.1.0
[mythcat@fedora ~]$ pip install pygame
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pygame in ./.local/lib/python3.12/site-packages (2.5.2)
[mythcat@fedora ~]$ pip install agentpy
...
Installing collected packages: scipy, networkx, kiwisolver, joblib, fonttools, dill, cycler, contourpy, pandas, multiprocess, matplotlib, SALib, agentpy
Successfully installed SALib-1.5.1 agentpy-0.1.5 contourpy-1.3.0 cycler-0.12.1 dill-0.3.8 fonttools-4.53.1 joblib-1.4.2 kiwisolver-1.4.7 matplotlib-3.9.2 multiprocess-0.70.16 networkx-3.3 pandas-2.2.2 scipy-1.14.1Tuesday, May 26, 2020
Python Qt5 : PyQt5 and PyGame compatibility with source code.
This tutorial tries to solve from the objectives related to solving and stabilizing compatibility errors between PyQt4 and PyQt5 and creating a common interface between PyQt5 and PyGame.
There is always the same problem in programming when the developer for some reason has to change classes, methods and functions and reusing the old code is no longer valid.
In this case, common or other errors occur, which leads to a waste of time.
I will present a simple way to solve these problems.
I really like to use the PyQt5 module to create interfaces for my python programs and scripts.
Like any programmer who hasn't fully used all A.P.I, I always use the old source code I programmed in the past.
What the developer says about the transition from PyQt4 to PyQt5 we can see on the official page.
Obviously, you will have to move on to things to know but it is quite difficult to always come back and read this content when you have programming errors.
Today, I wanted to make a simple drawing interface in PyGame that would be included in a PyQt5 interface.
I tried to use an old code created by me in PyQt4 but I realized that I had encountered errors before switching to the new PyQt5.
This compatibility problem generates errors and can be solved as follows: by knowing the exact solution and fixing errors in real time, studying the changes created by the developer or the classic search for errors.
My solution comes with the help of these solutions and requires a simple step using the commented source code.
To show you how simple it is to understand I will show you the source code for the interface I built that simply to solves the problem of understanding compatibility by reading the developer source code with simple and useful comments.
#the old import for PyQt4
#from PyQt4 import QtGui
#the new import for PyQt5
#from PyQt5 import QtCore, QtGui, QtWidgets
#class MainWindow(QtWidgets.QMainWindow, UI.MainUI.Ui_MainWindow):
from PyQt5 import QtGui
from PyQt5 import QtWidgets
import pygame
import sys
# old definition for PyQt4 for QWidget
#class ImageWidget(QtGui.QWidget):
class ImageWidget(QtWidgets.QWidget):
def __init__(self,surface,parent=None):
super(ImageWidget,self).__init__(parent)
w=surface.get_width()
h=surface.get_height()
self.data=surface.get_buffer().raw
self.image=QtGui.QImage(self.data,w,h,QtGui.QImage.Format_RGB32)
def paintEvent(self,event):
my_paint=QtGui.QPainter()
# the definitions for PyQt4 and PyQt5 use QtGui.QPainter()
my_paint.begin(self)
my_paint.drawImage(0,0,self.image)
my_paint.end()
# old definition for PyQt4 for QMainWindow
#class MainWindow(QtGui.QMainWindow):
class MainWindow(QtWidgets.QMainWindow):
def __init__(self,surface,parent=None):
super(MainWindow,self).__init__(parent)
self.setFixedSize(640, 480)
self.setCentralWidget(ImageWidget(surface))
# this part of source code need to be updated if you want to use animation
# init PyGame
pygame.init()
# define a surface
my_surface=pygame.Surface((640,480))
# fill the surface, see https://www.pygame.org/docs/ref/surface.html#pygame.Surface.fill
my_surface.fill((0,0,255,176))
# draw circle see https://www.pygame.org/docs/ref/draw.html#pygame.draw.circle
pygame.draw.circle(my_surface,(0,0,127,255),(76,76),76)
# draw ellipse (surface, color(R,G,B), size (x,y,x+dx, y+y+dy) )
pygame.draw.ellipse(my_surface,(127,0,0,0),(0,0,12,76))
# this part of source code will show
# the my_surface created with PyGame in PyQt5
# old definition for PyQt4
#app=QtGui.QApplication(sys.argv)
app=QtWidgets.QApplication(sys.argv)
my_window=MainWindow(my_surface)
my_window.show()
app.exec_()
Sunday, April 19, 2020
Python 3.8.2 : New release 2.3.2 for Pygame Menu.
Today, the development team come with this infos from the GitHub comes with a new release version 2.3.2.
Python library that can create a simple menu for the pygame application. Supports:
Let's start the tutorial with python install on Windows 10 using the installer from here.
Use these settings from images:


Download get-pip.py to a folder on your computer.
Open a command prompt and navigate to the folder containing get-pip.py.
Run the following command:

Python library that can create a simple menu for the pygame application. Supports:
- Textual menus
- Buttons
- Lists of values (selectors) that can trigger functions when pressing return or changing the value
- Input text
- Color input
Let's start the tutorial with python install on Windows 10 using the installer from here.
Use these settings from images:
Download get-pip.py to a folder on your computer.
Open a command prompt and navigate to the folder containing get-pip.py.
Run the following command:
python get-pip.py
Then update the path:C:\Projects\Python\pygame-menu>python -m pip install --upgrade pip
Collecting pip
Downloading https://files.pythonhosted.org/packages/54/0c/d01aa759fdc501a58f431
eb594a17495f15b88da142ce14b5845662c13f3/pip-20.0.2-py2.py3-none-any.whl (1.4MB)
|████████████████████████████████| 1.4MB 819kB/s
Installing collected packages: pip
Found existing installation: pip 19.2.3
Uninstalling pip-19.2.3:
Successfully uninstalled pip-19.2.3
Successfully installed pip-20.0.2
You need to install pygame python module:C:\Projects\Python\pygame-menu>pip install pygame
Collecting pygame
Downloading pygame-1.9.6-cp38-cp38-win_amd64.whl (4.8 MB)
|████████████████████████████████| 4.8 MB 819 kB/s
Installing collected packages: pygame
Successfully installed pygame-1.9.6
The last step is to install the Pygame Menu with git tool and documentation with pip tool:
$ git clone https://github.com/ppizarror/pygame-menu
Cloning into 'pygame-menu'...
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 5649 (delta 3), reused 7 (delta 2), pack-reused 5640
Receiving objects: 100% (5649/5649), 12.99 MiB | 5.52 MiB/s, done.
Resolving deltas: 100% (4289/4289), done.
...
C:\Projects\Python\pygame-menu>pip install -e .[doc]
The result with of how these python module with a simple example:C:\Projects\Python\pygame-menu\pygame_menu\examples>python game_selector.py
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
...
Posted by
Cătălin George Feștilă
Labels:
2020,
pygame,
Pygame Menu,
python,
python 3,
python3,
tutorial,
tutorials
Wednesday, July 26, 2017
The gtts python module.
This python module named gtts will create an mp3 file from spoken text via the Google TTS (Text-to-Speech) API.
The installation of the gtts python module under Windows 10.
You need to type the text into quotes also you will get an error.
The result will be one audio file named output.wav and play it by pygame python module.
This uses the default voices for all languages. I don't find a way to change this voices with python.
The installation of the gtts python module under Windows 10.
C:\Python27\Scripts>pip install gtts
Collecting gtts
Downloading gTTS-1.2.0.tar.gz
Requirement already satisfied: six in c:\python27\lib\site-packages (from gtts)
Requirement already satisfied: requests in c:\python27\lib\site-packages (from gtts)
Collecting gtts_token (from gtts)
Downloading gTTS-token-1.1.1.zip
Requirement already satisfied: chardet<3 .1.0="">=3.0.2 in c:\python27\lib\site-packages (from requests->gtts)
Requirement already satisfied: certifi>=2017.4.17 in c:\python27\lib\site-packages (from requests->gtts)
Requirement already satisfied: idna<2 .6="">=2.5 in c:\python27\lib\site-packages (from requests->gtts)
Collecting urllib3<1 .22="">=1.21.1 (from requests->gtts)
Using cached urllib3-1.21.1-py2.py3-none-any.whl
Installing collected packages: gtts-token, gtts, urllib3
Running setup.py install for gtts-token ... done
Running setup.py install for gtts ... done
Found existing installation: urllib3 1.22
Uninstalling urllib3-1.22:
Successfully uninstalled urllib3-1.22
Successfully installed gtts-1.2.0 gtts-token-1.1.1 urllib3-1.21.11>2>3>
Let's see a basic example:from gtts import gTTS
import os
import pygame.mixer
from time import sleep
user_text=input("Type your text: ")
translate=gTTS(text=user_text ,lang='en')
translate.save('output.wav')
pygame.mixer.init()
path_name=os.path.realpath('output.wav')
real_path=path_name.replace('\\','\\\\')
pygame.mixer.music.load(open(real_path,"rb"))
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
sleep(1)
The text will be taken by input into a user_text variable.You need to type the text into quotes also you will get an error.
The result will be one audio file named output.wav and play it by pygame python module.
This uses the default voices for all languages. I don't find a way to change this voices with python.
Posted by
Cătălin George Feștilă
Labels:
2.7,
2017,
gtts,
pygame,
python,
python modules,
tutorial,
tutorials
Sunday, October 2, 2016
Another simple effect with pygame.
The pygame module come with many features for users.
I used the pygame version to make one simple tutorial about pallete functions :
>>> print pygame.version.ver
1.9.2b1
The result of my tutorial is this:

I used the pygame version to make one simple tutorial about pallete functions :
>>> print pygame.version.ver
1.9.2b1
The result of my tutorial is this:

Posted by
Cătălin George Feștilă
Labels:
2.7,
2016,
8bits,
blur effect,
module,
modules,
pygame,
python,
python modules,
script,
tutorial,
tutorials
Thursday, September 22, 2016
Another learning python post with pygame.
This is a simple python script with pygame python module.
I make it for for educational purposes for the children.
I used words into romanian language for variables, functions and two python class.
See this tutorial here
I make it for for educational purposes for the children.
I used words into romanian language for variables, functions and two python class.
See this tutorial here
Sunday, December 21, 2014
pygame - using sound, mixer, volume, channels, fade-in and out effect .
PyGame module come with sound feature and this allow users to test some effects.
The next tutorial show you how to deal with pygame sound effect.
After, you can test all effects with python version 3.4.1 .
I used keys to change effects. The song is a ogg file.
I used this sample from a recording of of the album Through the Devil Softly by the artist Hope Sandoval and The Warm Inventions from here.
The next tutorial show you how to deal with pygame sound effect.
After, you can test all effects with python version 3.4.1 .
I used keys to change effects. The song is a ogg file.
I used this sample from a recording of of the album Through the Devil Softly by the artist Hope Sandoval and The Warm Inventions from here.
Posted by
Cătălin George Feștilă
Labels:
2014,
pygame,
python 3,
python modules,
tutorial,
tutorials
Friday, August 5, 2011
Installing and using pygame module in Windows XP.
You must have one of these versions of python installed:
2.6 , 2.7 , 3.1 or 3.2
... 32 bits or 64 bits.
Take the version you need from here.
Just run the executable and it will automatically install the python.
You can check if it runs:
python
Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
>>> from pygame import *On the same site you can find other modules required. You can try them.
Subscribe to:
Posts (Atom)