我今天在写弹球游戏的代码,游戏运行正常,但是只要一到游戏结束,就会显示一大串的错误提示:
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🙇