谁能帮帮我

我今天在写弹球游戏的代码,游戏运行正常,但是只要一到游戏结束,就会显示一大串的错误提示:

Traceback (most recent call last):
  File "C:\Users\郭丽健\Desktop\新建文本文档.py", line 75, in <module>
    messagebox.showinfo(title = '游戏结束', massage = '你的分数为:' + str(score))
  File "C:\Users\郭丽健\AppData\Local\Programs\Python\Python38\lib\tkinter\messagebox.py", line 84, in showinfo
    return _show(title, message, INFO, OK, **options)
  File "C:\Users\郭丽健\AppData\Local\Programs\Python\Python38\lib\tkinter\messagebox.py", line 72, in _show
    res = Message(**options).show()
  File "C:\Users\郭丽健\AppData\Local\Programs\Python\Python38\lib\tkinter\commondialog.py", line 44, in show
    s = w.tk.call(self.command, *w._options(self.options))
_tkinter.TclError: bad option "-massage": must be -default, -detail, -icon, -message, -parent, -title, or -type

我的游戏源代码是这样的:

from tkinter import *
from tkinter import messagebox
import random
import time

class Ball:
    def __init__(self, cv, paddl, color):
        self.canvas = cv
        self.paddle = paddle
        self.id = cv.create_oval(10,10,25,25,fill = color)
        starts = [-3,-2,-1,1,2,3]
        random.shuffle(starts)
        self.x = starts[0]
        self.y = -3
        self.canvas_height = self.canvas.winfo_height()
        self.canvas_width = self.canvas.winfo_width()
        self.hit_bottom = False
    def hit_paddle(self,pos):
        global score
        paddle_pos = self.canvas.coords(self.paddle.id)
        if pos[2] >= paddle_pos[0] and pos[0] <= paddle_pos[2]:
            if pos[3] >= paddle_pos[1] and pos[3] <= paddle_pos[3]:
                score += 1
                return True
        return False
    def draw(self):
        self.canvas.move(self.id, self.x, self.y)
        pos = self.canvas.coords(self.id)
        if pos[0] <= 0:
            self.x = 3
        if pos[2] >= self.canvas_width:
            self.x = -3
        if self.hit_paddle(pos) == True:
            self.y = -3
        if pos[1] <= 0:
            self.y = 3
        if pos[3] >= self.canvas_height:
            self.hit_bottom = True
class Paddle:
    def __init__(self, cv, color):
        self.canvas = cv
        self.id = cv.create_rectangle(0,0,100,10,fill = color)
        self.canvas.move(self.id, 200, 300)
        self.x = 0
        self.canvas_width = self.canvas.winfo_width()
        self.canvas.bind_all('<KeyPress-Left>',self.turn_left)
        self.canvas.bind_all('<KeyPress-Right>',self.turn_right)
    def draw(self):
        self.canvas.move(self.id, self.x, 0)
        pos = self.canvas.coords(self.id)
        if pos[0] <= 0:
            self.x = 0
        elif pos[2] >= self.canvas_width:
            self.x = 0
    def turn_left(self,evt):
        self.x = -2
    def turn_right(self,evt):
        self.x = 2

root = Tk(className = '弹弹珠')
root.resizable(0,0)
score  = 0
cv = Canvas(root, width = 500, height = 400, bd = 0, highlightthickness = 0)
cv.pack()
root.update()

paddle = Paddle(cv, "green")
ball = Ball(cv, paddle, "red")

while 1:
    if ball.hit_bottom == False:
        ball.draw()
        paddle.draw()
    else:
        messagebox.showinfo(title = '游戏结束', massage = '你的分数为:' + str(score))
        break
    root.update_idletasks()
    root.update()
    time.sleep(0.01)

虽然有些长,但是我敢肯定游戏运行正常,就是一道结束就出现这个东西。。。

游戏运行效果:

 求各位大佬指点qwq🙇‍

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值