Python TkMessageBox - 无模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38181710/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TkMessageBox - No Module
提问by Tom Lowbridge
import TkMessageBox
When I import TkMessageBox it displays the messsge 'ImportError: No module named 'TkMessageBox'.
当我导入 TkMessageBox 时,它会显示消息'ImportError: No module named 'TkMessageBox'。
As far as I know im using python 3.3.2 and Tk 8.5.
据我所知,我使用的是 python 3.3.2 和 Tk 8.5。
Am I using the wrong version of python or importing it wrong ?
我是否使用了错误版本的 python 或导入错误?
Any answers would be extremely useful. Alternatively is there something similar in the version i am using?
任何答案都会非常有用。或者,我正在使用的版本中是否有类似的东西?
回答by Billal Begueradj
In Python3.x things have changed a little bit:
在 Python3.x 中,事情发生了一些变化:
>>> import tkinter
>>> import tkinter.messagebox
>>>
I mean what we call tkMessageBox
in Python2.x becomes tkinter.messagebox
in Python3.x
我的意思是我们tkMessageBox
在 Python2.xtkinter.messagebox
中所说的变成 了 Python3.x
回答by Hung Truong
In Python 2.x, to import, you'd say import tkMessageBox
. But in Python 3.x, it's been renamed to import tkinter.messagebox
.
在 Python 2.x 中,要导入,您会说import tkMessageBox
. 但是在 Python 3.x 中,它被重命名为 import tkinter.messagebox
。
Hope it helped :))
希望它有所帮助:))
回答by Poikilos
If you don't want to have to change the code for Python 2 vs Python 3, you can use import as:
如果您不想更改 Python 2 与 Python 3 的代码,您可以使用 import 为:
try:
from tkinter import messagebox
except:
# Python 2
import tkMessageBox as messagebox
Then using messagebox as follows will work in either version:
然后按如下方式使用消息框将适用于任一版本:
messagebox.showerror("Error", "Message.")
回答by Suraj Verma
for python 3.x
对于 python 3.x
import tkinter
import tkinter.messagebox
导入 tkinter
导入 tkinter.messagebox
回答by Diversity infinie YT
from tkinter import messagebox sous Python 3 messagebox.showinfo(title=None, message=None, **options)
from tkinter import messagebox sous Python 3 messagebox.showinfo(title=None, message=None, **options)