Что значит ошибка "RuntimeError: The FreeType 2 library hasn't been initialized"?
26.12.2020, 16:55. Показов 2457. Ответов 0
При запуске кода выдает ошибку "RuntimeError: The FreeType 2 library hasn't been initialized"
Полный текст ошибки:
Код
Traceback (most recent call last):
File "/home/arida/codes_study/my/trpg/main.py", line 5, in <module>
so.open_menu()
File "/home/arida/codes_study/my/trpg/so.py", line 66, in open_menu
open_map()
File "/home/arida/codes_study/my/trpg/so.py", line 83, in open_map
7, (255, 255, 255), (10, 10), 'open_menu'))
File "/home/arida/codes_study/my/trpg/classes_def.py", line 14, in __init__
self.title, self.t_rect = pygame.freetype.Font(FONT, t_size).render(text, t_rgb)
RuntimeError: The FreeType 2 library hasn't been initialized
classes_def.py:
Python | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
| import pygame.freetype
FONT = 'font.ttf'
class Button:
def __init__(self, text, size, rgba, pos, t_size, t_rgb, t_pos, act='None'):
self.rect = pygame.Surface(size)
self.rect.fill((rgba[0], rgba[1], rgba[2]))
self.rect.set_alpha(rgba[3])
self.pos = pos
self.check_rect = pygame.Rect((*pos, *size))
self.title, self.t_rect = pygame.freetype.Font(FONT, t_size).render(text, t_rgb)
self.t_rect.topleft = t_pos
self.act = act
def draw_rect(self):
return [self.rect, self.pos]
def draw_text(self):
return [self.title, self.t_rect]
def list_of_orders(self):
order = 0
if self.act.find('open') > -1:
order += 100
if self.act.find('map') > -1:
order += 1
if self.act.find('menu') > -1:
order += 2
elif self.act.find('set') > -1:
order += 200
return order
def acting(self, event):
if self.check_rect.collidepoint(*event.pos):
return self.list_of_orders() |
|
so.py:
Python | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
| import pygame.freetype
import sys
import pygame.constants
import classes_def as cd
FPS = 30
W = 1366
H = 748
CAPTION = 'TRPG Helper'
'''
DOCUMENTATION FOR ACTION ID
100 200
1 menu-map
2 any-menu
'''
def open_menu():
sc = pygame.display.set_mode((600, 600))
clock = pygame.time.Clock()
pygame.display.set_caption(CAPTION)
back_t = pygame.image.load('textures/back.jpg')
back_rect = back_t.get_rect()
sc.blit(back_t, back_rect)
buttons = list()
buttons.append(cd.Button('Добро пожаловать в TRPG helper!',
(540, 540), (5, 10, 3, 200), (20, 20),
30, (255, 255, 255), (30, 30)))
buttons.append(cd.Button('Карты',
(300, 50), (11, 15, 10, 158), (60, 100),
30, (255, 255, 255), (70, 110), 'open_map'))
for button in buttons:
sc.blit(*button.draw_rect())
sc.blit(*button.draw_text())
mark = -1
while True:
clock.tick(FPS)
if mark != -1:
break
for event in pygame.event.get():
if mark != -1:
break
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
for i in buttons:
id = i.acting(event)
if 99 < id < 200:
mark = id
pass
if event.type == pygame.KEYDOWN and event.key == pygame.K_m:
mark = 101
pygame.display.update()
pygame.quit()
if mark == 101:
open_map()
def open_map():
# pygame.init()
sc = pygame.display.set_mode((W, H), pygame.RESIZABLE)
clock = pygame.time.Clock()
pygame.display.set_caption(CAPTION)
back_t = pygame.image.load('textures/map_back.jpg')
back_t = pygame.transform.scale(back_t, (W, H))
back_rect = back_t.get_rect()
sc.blit(back_t, back_rect)
buttons = list()
buttons.append(cd.Button('<',
(10, 10), (0, 0, 0, 200), (10, 10),
7, (255, 255, 255), (10, 10), 'open_menu'))
for button in buttons:
sc.blit(*button.draw_rect())
sc.blit(*button.draw_text())
while True:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
pygame.display.update() |
|
main.py:
Python | 1
2
3
4
5
| import so
import pygame
pygame.init()
so.open_menu() |
|
Добавлено через 44 минуты
Вопрос исчерпан. Проблема была в закомментированной строке
0
|