Pygame not using specified font

2024/11/16 3:34:16

So I am having a problem in pygame where I specify the font and size to use, but when my program is run, the font and size are the default.

Here is where I define the text

def font(self):'''*****FATAL - THIS LINE CAUSES ERROR (When compiled to .exe using cx_freeze)*****'''#font = pygame.font.SysFont("Coure", 20)font_color = (0, 0, 0)font = pygame.font.Font("coure.fon", 20)self.text = font.render("Level "+str(self.level) + " " + self.name + " Health " + str(self.health), True, font_color)

The line commented out under the "Fatal" comment works perfectly when run from the editor, however causes this error once it is run as an .exe

Fatal Python error: (pygame parachute) Segmentation Fault
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\pygame\pkgdata.py", line 67, in   getResource
return open(os.path.normpath(path), 'rb')
FileNotFoundError: [Errno 2] No such file or directory:    'C:\\Users\\Jared\\Desktop\\Python\\Boss Battle\\build\\exe.win32-3.4\\library.zip\\pygame\\freesansbold.ttf'

I don't have the freesansbold font installed on my computer, but that shouldn't matter, since it should be looking for the coure font in the folder of the game. The weird thing is that I say "Coure" and the file is named "coure.fon", but when I write that, it is unrecognized.

I guess Im looking for some guidence on how to fix either the error, or how to define which text file I want it to use. Thanks for any help!

Answer

Open up your pygame package folder. It should be something like C:\Python34\Lib\site-packages\pygame. There should be a True Type Font File titled freesansbold.ttf. Copy that file then open the folder containing your exe program. There should be a zipped file called library. Open it up and go to the pygame folder inside the zipped file. Should look something like this \build\exe.win32-3.4\library.zip\pygame. And just paste the freesansbold.ttf file in that folder and it should work perfectly. The freesansbold font comes with the pygame package, but for some reason py2exe and cx_Freeze don't include it, so you have to add it manually.

https://en.xdnf.cn/q/118977.html

Related Q&A

port management in python/flask application

I am writing a REST API using the micro framework Flask with python programming language. In the debug mode the application detect any change in source code and restart itself using the same host and p…

using def with tkinter to make simple wikipedia app in python

I am beginner in python. I am trying to make a python wiki app that gives you a summary of anything that you search for. My code is below:import wikipediaquestion = input("Question: ")wikiped…

Only length-1 arrays can be converted to Python scalars with log

from numpy import * from pylab import * from scipy import * from scipy.signal import * from scipy.stats import * testimg = imread(path) hist = hist(testimg.flatten(), 256, range=[0.0,1.0])[0] hist…

Deploying Django with apache using wsgi.py

Im trying to deploy a Django project on a linode server that has apache, some other django projects and a php project on it. Also my project is in a virualenv and the other django projects arent.My Dja…

Building a decision tree using user inputs for ordering goods

I am trying to program a decision tree to allow customers to order goods based on their input. So far, I have devised a nested if-elif conditional structure to decide if customer want to order what or…

How to de-serialize the spark data frame into another data frame [duplicate]

This question already has answers here:Explode array data into rows in spark [duplicate](3 answers)Closed 4 years ago.I am trying to de-serialize the the spark data frame into another data frame as exp…

How to pull specific key from this nested dictionary?

{"newData": [{"env1": [{"sins": [{"host": "test.com","deployTime": "2015-07-23 11:54 AM",…}],"name": “hello”}, {"…

Dropping cell if it is NaN in a Dataframe in python

I have a dataframe like this.Project 4 Project1 Project2 Project3 0 NaN laptio AB NaN 1 NaN windows ten NaN 0 one NaN NaN 1 …

How can I iterate through excel files sheets and insert formula in Python?

I get this error TypeError: Workbook object is not subscriptablewhen i run this code import xlsxwriter from openpyxl import load_workbookin_folder = rxxx #Input folder out_folder = rxxx #Output folde…

How to bind all frame widgets to Enter event

I the following code I want to bind all frame1 items to <Enter> Event, but it does not work. I mean canvas.focus_set() does not take effect. How can I solve my problem?for w in frame1.winfo_chil…