python 2.7 - 没有名为 tkinter 的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18729147/
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
python 2.7 - no module named tkinter
提问by BuroBernd
i am on mac os x 10.8, using the integrated python 2.7. i try to learn about tkinter with tutorials like thisfor python 2.7 (explicitly not 3) they propose the following code:
我在 mac os x 10.8 上,使用集成的 python 2.7。我尝试通过python 2.7(明确不是 3)这样的教程来了解 tkinter,他们提出了以下代码:
from tkinter import *
import tkinter.messagebox
however, this brings up the error:
然而,这带来了错误:
ImportError: No module named tkinter
using import.Tkinter with a capital t seems to work, but further commands like
使用带有大写 t 的 import.Tkinter 似乎有效,但进一步的命令如
import Tkinter.messagebox
don't (neither does tkinter.messagebox). I've had this problem with lots of tutorials. what's the thing with the capital / non-capital "T", and how do i get my python to work like it does in the tutorials? Thanks in advance!
不要(tkinter.messagebox 也没有)。我在很多教程中都遇到过这个问题。大写/非大写“T”有什么问题,我如何让我的 python 像教程中那样工作?提前致谢!
采纳答案by joaquin
In Tkinter (uppercase) you do not have messagebox.
You can use Tkinter.Message
or import tkMessageBox
在 Tkinter(大写)中,您没有消息框。您可以使用Tkinter.Message
或import tkMessageBox
This code is an example taken from this tutorial:
此代码是从本教程中获取的示例:
import Tkinter
import tkMessageBox
top = Tkinter.Tk()
def hello():
tkMessageBox.showinfo("Say Hello", "Hello World")
B1 = Tkinter.Button(top, text = "Say Hello", command = hello)
B1.pack()
top.mainloop()
Your example code refers to a python installation >= py3.0. In Python 3.x the old good Tkinter has been renamed tkinter.
您的示例代码指的是 python 安装 >= py3.0。在 Python 3.x 中,旧的好Tkinter 已重命名为 tkinter。
回答by Alex Quinn
Tkinter
(capitalized) refers to versions <3.0.
Tkinter
(大写)是指版本 <3.0。
tkinter
(all lowecase) refers to versions ≥3.0.
tkinter
(全部小写)是指版本≥3.0。
回答by Nuclear_Man_D
For python 2.7 it is Tkinter, however in 3.3.5 it is tkinter.
对于 python 2.7,它是 Tkinter,但在 3.3.5 中它是 tkinter。
回答by Boaz.B
For python 2.7 use Cap Letters Tkinter but for >3.0 use small letter tkinter
对于 python 2.7 使用大写字母 Tkinter 但对于 >3.0 使用小写字母 tkinter