Can't create games with pygame

2019-08-25 02:23发布

问题:

I make a game with python 2.5 and pygame.

but,I can't complete make. because this errors occured.

C:\Python26\TypeType\src\dist\Main.exe:8: RuntimeWarning: use font: MemoryLoadLibrary failed loading pygame\font.pyd
Traceback (most recent call last):
  File "Main.py", line 8, in <module>
  File "pygame\__init__.pyo", line 70, in __getattr__
NotImplementedError: font module not available
Traceback (most recent call last):
  File "Main.py", line 8, in <module>
  File "pygame\sysfont.pyo", line 253, in SysFont
RuntimeError: default font not found 'freesansbold.ttf'

Perhaps I think that the reason is because it used an object called sysfont. (Because I had the programs that did not use sysfont on an execute file and was able to start with the PC which was not installed Python in) What's wrong . sorry I'm begginer.

EDIT I can find Python2.5\Lib\site-packages\pygame\freesansbold.ttf

but same error occured.. Where may I copy freesansbold.ttf

回答1:

A simple solution would be to simply load the font directly instead of using sysfont. Just use the pygame.font.Font class and directly load a ttf file. This will also make it easier to use py2exe, and you can choose exactly the font you want.



回答2:

It looks like you don't have the freesansbold.ttf file on your computer in an accessible fonts folder. This font should have come with Pygame in the lib directory.

Check the installation folder for your copy of Pygame, and if it's there, modify your Python installation's font path to include that directory. If not, you'll need to find a copy or download a newer version of Pygame.



回答3:

You probably found a solution but i want to give one for other. Create you game with pygame. Then, unzip the librairy file. Go to

PythonX.X\Lib\site-packages\pygame and copy freesansbold.ttf

Back to your library file that you unzipped and go to

library\pygame

Put freesansbold.ttf in and zip library.

Now, it's work ! :)