【发布时间】:2019-01-01 21:41:37
【问题描述】:
我目前正在做我自己的小项目,该项目是关于单击一个无意义的按钮。我正在使用 tkinter 和 peewee 在 python 中制作它,以便能够存储保存,以便用户/玩家可以从他们离开的地方继续。
当我制作“保存”功能时,但是当我在 peewee 中创建模型时,它给了我一个错误:
TypeError: 'str' 对象不可调用
我的模型类如下所示:
db = SqliteDatabase("scores.db")
class Score(Model):
save = CharField()
score = IntegerField()
class Meta:
database = db
保存进度的函数如下所示:
def save_progress():
global score_number
# score_number signifies the score of the game(how many times the button has been clicked)
saves_length = int(Score.select().count())
save = "save{}".format(saves_length+1)
Score.create(save=save, score=score_number)
错误来了:
Score.create(save=save, score=score_number)
我不明白为什么它说我正在调用一个字符串对象,因为我认为我不是。
有人可以向我解释一下我在代码中做错了什么吗?
谢谢!
安德烈
【问题讨论】:
标签: python python-3.x peewee