【发布时间】:2014-04-04 16:43:00
【问题描述】:
我一直在使用 Python 3.3.1 从《Python for Absolute Beginners》一书中进行编程。
我正在尝试使用以下代码将文本添加到屏幕。我需要继续使用 Python 3.3.1,但我认为书中的代码适用于 Python 2.X。
from livewires import games, color
class Pizza(games.Sprite):
"""A falling pizza"""
def __init__(self, screen, x,y, image, dx, dy):
"""Initialise pizza object"""
self.init_sprite(screen = screen, x = x, y = y, image = image, dx = dx, dy = dy)
SCREEN_WIDTH = 640
SCREEN_HEIGHT = 480
#main
my_screen = games.Screen(SCREEN_WIDTH, SCREEN_HEIGHT)
wall_image = games.load_image("wall.jpg", transparent = False)
pizza_image = games.load_image("pizza.jpg")
my_screen.set_background(wall_image)
games.Text(screen = my_screen, x = 500, y = 30, text = "Score: 1756521", size = 50, color =
my_screen.mainloop()
但是,当我运行这个程序时,我得到一个错误(见下文)
games.Text(screen = my_screen, x = 500, y = 30, text = "Score: 1756521", size = 50, color = color.black)
TypeError: __init__() got an unexpected keyword argument 'text'
希望你能帮忙
【问题讨论】:
-
games.Text() 正在创建一个对象,但定义该对象的类中的 __init__() 并不需要一个名为 text 的关键字参数,因此出现了异常。我建议你看看 games.Text 类中的 __init__()
标签: python python-3.x livewires