実現したいこと
python(3.11.1)でpygameを使用し、「hello!」というfontを表示させたい
前提
私はmacOSを使用し、公式サイトからpython(3.11.1)をダウンロードしました。
IDLEを使用しています。また、ターミナルにpip install pygame--preと打ち込み、pygameをダウンロードしました。
ここに質問の内容を詳しく書いてください。
コードを打つとpygamewindowが出てきて、黒い画面のままです。また、IDLEにエラーコード出てきており、解決できません。どのような対処をすれば、フォントが表示できるでしょうか?
お分かりになる方、よろしくお願い致します。
該当のソースコード
python(3.11.1)
1 2ソースコード 3```import pygame as pg,sys 4pg.init() 5screen=pg.display.set_mode((800,600)) 6font=pg.font.Font(None,50) 7textimg=font.render("hello!",True,pg.Color("BLUE")) 8while True: 9 screen.fill(pg.Color("WHITE")) 10 screen.blit(textimg,(200,100)) 11 pg.display.update() 12 for event in pg.event.get(): 13 if event.type == pg.QUIT: 14 pg.quit() 15 sys.exit() 16### エラーコード 17Warning (from warnings module): 18 File "/Users/nomuranaohiro/Documents/hello.py", line 4 19 font=pg.font.Font(None,50) 20RuntimeWarning: use font: dlopen(/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pygame/font.cpython-311-darwin.so, 2): Library not loaded: @loader_path/libfreetype.6.dylib 21 Referenced from: /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pygame/.dylibs/libfreetype.6.dylib 22 Reason: image not found 23(ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pygame/font.cpython-311-darwin.so, 2): Library not loaded: @loader_path/libfreetype.6.dylib 24 Referenced from: /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pygame/.dylibs/libfreetype.6.dylib 25 Reason: image not found) 26Traceback (most recent call last): 27 File "/Users/nomuranaohiro/Documents/hello.py", line 4, in <module> 28 font=pg.font.Font(None,50) 29 File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pygame/__init__.py", line 70, in __getattr__ 30 raise NotImplementedError(missing_msg) 31NotImplementedError: font module not available (ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pygame/font.cpython-311-darwin.so, 2): Library not loaded: @loader_path/libfreetype.6.dylib 32 Referenced from: /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pygame/.dylibs/libfreetype.6.dylib 33 Reason: image not found) 34ここに問題に対して試したことを記載してください。 35 36### 補足情報(FW/ツールのバージョンなど) 37ドキュメントにはhello.pyのファイルがあります。また、Libraryというファイルも同じ場所にあるのですが、それを押すと「アクセス権が無いため、表示できない」と表示されます。 38ここにより詳細な情報を記載してください。

あなたの回答
tips
プレビュー