我是设计Python Graphics的新手。我试图运行以下代码,但它给出了一个奇怪的错误。任何人都可以帮我解决这个错误吗?
from livewires import games, color
SCREEN_WIDTH=640
SCREEN_HEIGHT=480
my_screen=games.Screen(SCREEN_WIDTH,SCREEN_HEIGHT)
wall_image=games.load_image("wall.jpg", transparent=False)
my_screen.set_background(wall_image)
games.Text(screen=my_screen, x=500, y=30,
text="Score: 1756521", size=50,
colour=color.black)
my_screen.mainloop()
并且在执行此操作时我收到以下错误:
Exception NameError: "global name 'screen' is not defined" in <bound method Text.__del__ of <livewires.games.Text object at 0x02B14810>> ignored
Traceback (most recent call last):
File "C:\Python31\game_test.py", line 9, in <module>
colour=color.black)
TypeError: __init__() got an unexpected keyword argument 'text'
事实上,我查看了livewires games.py模块的源代码,如下所示
class Text(Object, ColourMixin):
"""
A class for representing text on the screen.
The reference point of a Text object is the centre of its bounding box.
"""
def __init__(self, screen, x, y, text, size, colour, static=0):
self.init_text (screen, x, y, text, size, colour, static)
.........
那我哪里出错???
答案 0 :(得分:0)
from livewires import games, color
没有此类模块color
,但colour
[proof link]
"C:\Python31\game_test.py"
请阅读模块docs。我不认为它支持python3。
该软件包已经在从1.5.2到2.4的Python版本中使用,但是游戏模块现在使用PyGame,它至少需要2.1版本。版本2.1遇到了Python 2.3及更高版本(或更具体地说包括Tk8.4)的一些兼容性问题,这些问题有望通过此修订进行更正。