为什么尝试创建 tkinter 消息框会导致 'module not callable' 错误?

Why does trying to create a tkinter messagebox cause a 'module not callable' error?

在这里,当我 运行 它并按 '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()

您正在像函数一样使用 messagebox

它实际上是一个模块,所以你不能调用它。

你应该使用像

这样的东西
tkinter.messagebox.showinfo("Snake","Have fun!")

因为消息框是一个模块而不是一个函数。