马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
众所周知,pygame zero 的程序运行方式有两种:
1. 普通运行
2. pgzrun xxx.py(.py文件里不用import pgzrun和pgzrun.go)
那么为什么我普通运行(IDLE,not pycharm)可以正常显示中文标题的窗口,pgzrun运行就会乱码?
(程序:WIDTH = 640
HEIGHT = 480
TITLE = '跑酷'
这样会乱码;import pgzrun
...
pgzrun.go()
且用普通方式运行就不会乱码。
我以为是GBK编码的问题,结果改了编码:TITLE = '跑酷'.encode().decode('utf-8')
就报错了pygame 2.1.3 (SDL 2.0.22, Python 3.9.9)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "C:\Users\防止偷窥\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\防止偷窥\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\防止偷窥\AppData\Local\Programs\Python\Python39\Scripts\pgzrun.exe\__main__.py", line 7, in <module>
File "C:\Users\防止偷窥\AppData\Local\Programs\Python\Python39\lib\site-packages\pgzero\runner.py", line 92, in main
exec(code, mod.__dict__)
File "paoku.py", line 4, in <module>
TITLE = '跑酷-Pgzero'.encode().decode('gbk')
UnicodeDecodeError: 'gbk' codec can't decode byte 0xbf in position 8: illegal multibyte sequence
|