【问题标题】:IDLE closing when I try to run Pygame [duplicate]当我尝试运行 Pygame 时,IDLE 关闭 [重复]
【发布时间】:2014-06-07 13:54:02
【问题描述】:

每当我尝试运行一些代码时,IDLE 都会关闭。我已经卸载了 IDLE 并再次安装了两次。我还测试了其他 python 文件,以确保它在我的代码中没有问题。

我打开 Python 命令行,从 idlelib import idle 写入,打开一个 Python 文件并尝试运行它,结果如下:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python34\lib\tkinter\__init__.py", line 1487, in __call__
    return self.func(*args)
  File "C:\Python34\lib\idlelib\MultiCall.py", line 179, in handler
    r = l[i](event)
  File "C:\Python34\lib\idlelib\ScriptBinding.py", line 127, in run_module_event

    return self._run_module_event(event)
  File "C:\Python34\lib\idlelib\ScriptBinding.py", line 141, in _run_module_event

    code = self.checksyntax(filename)
  File "C:\Python34\lib\idlelib\ScriptBinding.py", line 102, in checksyntax
    return compile(source, filename, "exec")
TypeError: source code string cannot contain null bytes

我现在没有使用 Tkinter,我正在使用 Pygame。我也知道 IDLE 是用 Tkinter 编写的。 我正在运行 Python 3.4 有谁知道这意味着什么?或者更好的是,如何让 IDLE 再次工作?

更新:只有 PYGAME 程序才会崩溃

【问题讨论】:

  • 如何打开 Python 文件并运行它?
  • 我去文件,打开。选择我的 python 文件,然后按 F5。另外,我检查了一个不使用 Pygame 的文件,它运行良好,可能就是这样。
  • 尝试以正常方式运行IDLE,即通过开始菜单| 选择它。 Python 3.4 |空闲(Python GUI)。
  • 错误信息的意思是:您正在运行的文件有一个空 (0) 字节或代码,这是不允许的。消息来自内置编译函数,而不是 IDLE。如果您尝试使用“python -m path/to/myfile.py”从控制台运行文件,您应该会看到相同的消息。你是什​​么操作系统?如果在 Windows 上,您可以在资源管理器中右键单击该文件并选择“运行”。
  • “Pygame 程序”是指您编写的具有“import pygame”的程序。由于 compile 不执行任何操作,我不明白为什么该导入会有所作为。你有可能有空代码的 pygame 程序的模板吗?

标签: python pygame python-idle


【解决方案1】:

要测试文件的空字节/代码,请尝试以下操作:

with open('myfile.py') as f:
    for i, line in enumerate(f, 1):  # lines begin with 1
       for j, char in enumerate(line):
           if not char:
               print('Line %s: col %s' % (i,j))

【讨论】:

    猜你喜欢
    • 2011-09-20
    • 1970-01-01
    • 1970-01-01
    • 2018-11-13
    • 2019-07-18
    • 1970-01-01
    • 2020-10-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多