在此,当我运行它并按下'yes'
选项想要播放时,我收到错误消息
line 36, in <module>
tkinter.messagebox("Snake","Have fun!")
TypeError: 'module' object is not callable
我不确定为什么我收到此错误,因为我多次导入messagebox
模块但仍然无法正常工作。任何人都可以提供改进或解释吗?
代码:
#importing modules that I need
import tkinter
from tkinter import *
from msvcrt import *
#importing messagebox module separately
from tkinter import messagebox
#the function that closes the window
def closeitall(self):
board.destroy()
#creating the game board
board=tkinter.Tk()
#setting background colour
board.configure(background="#B3C9D0")
#sets title of board window
board.title("Snake")
#sets size of board
board.geometry("700x500")
#makes it so that the board can't be resized
board.resizable(0,0)
#asks question
play=messagebox.askquestion("Snake","Do you want to play snake?")
#closes window if answer is no
if play=="no":
closeitall(board)
#creates a messagebox
else:
tkinter.messagebox("Snake","Have fun!")
#closes board when escape key pressed
board.bind("<Escape>",closeitall)
board.mainloop()
答案 0 :(得分:3)
您应该使用类似
的内容tkinter.messagebox.showinfo("Snake","Have fun!")
因为messagebox是一个模块,而不是一个函数。
答案 1 :(得分:2)
您正在使用messagebox
功能。
它实际上是一个模块,因此您无法调用它。