本文介绍了pygame 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我最近为 python 安装了 pygame 扩展,但我在让它工作时遇到了一些问题.我使用的是 python 版本 2.7.8,我尝试过的 pygame 版本来自 here,得到了 2.7 32 位版本.我还尝试了 pygame.org 站点并下载了 pygame-1.9.2a0.win32-py2.7.msi.我使用我在网上找到的代码从这里测试pygame但是当我尝试运行该程序时,出现的只是一个黑色窗口,顶部带有 pygame 图标.如果我尝试单击任意位置或执行任何操作,程序将崩溃并显示程序无响应"窗口.有人可以告诉我出了什么问题或者我可以尝试什么吗?

So I recently installed the pygame extension for python, but I am having some trouble getting it to work. I am using python version 2.7.8, and on of the pygame versions I have tried are from here, got the 2.7 32 bit version. I also tried the pygame.org site and downloaded pygame-1.9.2a0.win32-py2.7.msi. I used a code I found online to test pygame out from herebut when I try to run the program, all that comes up is a black window with the pygame icon on the top. If I try and click anywhere or do anything the program crashes with a "program not responding" window. Can somebody tell me what is wrong or things I can try?

推荐答案

我尝试运行代码并收到一条错误消息:

I tried running the code and got an error message saying:

TypeError: super() takes at least 1 argument (0 given)

所以我的结论是视频中的那个人使用的是 Python3.x,因为如果我没有错的话 super() 在 3.x 中不需要任何参数

So My conclusion Is that the guy in the video is using Python3.x because if I'm not misstaking super() doesn't require any arguments in 3.x

我不知道您是否收到此错误消息,但您至少可以尝试我的解决方案:

I don't know if you got this error message but You could at least try my solution:

在 Python 2.7.8 super() 需要参数,所以你需要像这样修改代码:

In Python 2.7.8 super() needs arguments, so you need to modify the code like this:

super(Player, self).__init__()  #Line 48 in the example you linked to
super(Wall, self).__init__()    # Line 97 in the example

对我来说修复了它.使用 pygame 等 GUI 库时需要考虑的另一件事是,python GUI 会干扰 pygame 代码,因为 pygame 也尝试创建 GUI.为避免这种情况,您可以从例如 cmd 运行程序.

for me that fixed it. Another thing woth thinking about when working with GUI libraries like pygame is that the python GUI can interfere with the pygame code because pygame also tries to create a GUI. To avoid this you can run the program from, for example cmd instead.

这篇关于pygame 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 22:28