The basics of making a window screensaver with Python and the Pygame library  

This section assumes that you have pygame installed as a library for Python as well as a basic understanding of creating python code.

The short version: All screensavers for windows are executables with their extension renamed to “.scr”

The slightly longer version:

In terms of pygame, you must have two things in your code.

  1. import pygame._view must be in your import statements so the console window goes away but leaves the program running.
  2. pygame.display.set_mode always uses the FULLSCREEN flag wherever it appears in your code.

If those two requirements are set, get py2exe and create a file named setup.py with the following:

from distutils.core import setup
import py2exe, sys, os


sys.argv.append('py2exe')


setup(
....options = {'py2exe': {'bundle_files': 1}},
....windows = [{'script': "pyBCD_screensaver.py"}],
....zipfile = None,
)

You need the files bundled so you get only one file instead of a mind numbing quantity of DLL files.

Execute the setup file in your command prompt window: python py2exe setup.py

Two new sub directories have been created. Look under distro for your new file.

The resulting EXE will be relatively big. This one is 10 MB. That’s the tradeoff for the convenience of writing in python.

Now test your new EXE file. If it works as expected, rename the extension to SCR and copy it your windows directory.

Now you’re all set. You can adapt this for your own screensaver project.

I hope you found this post useful.

I accept tips in bitcoin. :-)  If you cannot send me bitcoin, either from lack of funds or because you have no idea what a bitcoin is, send me a picture of your computer running the screensaver and I will put it in my pyBCD slideshow. Include a caption for the media library.

Any questions? Leave a comment or contact me directly.

Enjoy!

Pages: 1 2 3

2 Responses to pyBCD Binary Clock Screensaver 1.0

  • Thomas says:

    Could you post a little bit about how you turned a Python program into a Windows screensaver?

    • Chris Uzal says:

      All set. You should be able to follow my instructions. Let me know if you need anything else cleared up.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


− 3 = three

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>