简体   繁体   English

为什么我不能在Python中使用ttk?

[英]Why can't I use ttk in Python?

When I type from Tkinter import ttk it says that there is no module named ttk , and also on many websites online the t in tkinter is always lowercase , but when I type tkinter in Python it throws an error. 当我键入from Tkinter import ttk它说,没有模块名为ttk ,并在许多网站上在线ttkinter永远是小写的 ,但是当我输入tkinter Python中它抛出一个错误。 Why is that? 这是为什么?

There is nothing wrong with the case. 这个案子没有错。 As other answer specified - its Tkinter in Python 2.x and tkinter in Python 3.x version. 正如其他答案所指定的那样 - 它在Python 2.x中的Tkinter和在Python 3.x版本中的tkinter

In addition ttk was a separate module in Python 2.x and its a submodule of Tkinter in Python 3.x 另外, ttk是Python 2.x中的一个单独模块,它是Python 3.x中Tkinter的子模块

So in Python 2.x you would import ttk as 所以在Python 2.x中你可以导入ttk as

from Tkinter import *
import ttk

And in Python 3.x you would import ttk as 在Python 3.x中你可以导入ttk as

from tkinter import *
from tkinter.ttk import *

or 要么

from tkinter import ttk

python 2.6中的Tkinter是大写的,在python 3中它是小写的, tkinter

To use ttk from Python, you need a separate download and install which you can find here . 要使用Python中的ttk,您需要单独下载并安装,您可以在此处找到。

Python is case-sensitive (like most programming languages), but "many websites" are not (like most human beings) so it's a perfectly understandable sloppiness on those "many websites"' part to spell Tkinter in the wrong case. Python是区分大小写的(就像大多数编程语言一样),但“很多网站”并不像大多数人类一样,所以对于那些“很多网站”来说,在错误的情况下拼写Tkinter是一个完全可以理解的邋。。 Hey, you yourself break English rules by using lower case in words starting sentences, twice in your short question, you should sympathize with the use of wrong casing in those "many websites", and definitely shouldn't be surprised by it! 嘿,你自己打破英语规则,在单词开头的句子中使用小写,在你的简短问题中使用两次 ,你应该同情在那些“很多网站”中使用错误的套管,绝对不应该对它感到惊讶

I have met the same question with you.The fact is in Python2.x, the way to import module is type capitalized "T" in "tkinter": 我遇到了同样的问题。事实是在Python2.x中,导入模块的方式是在“tkinter”中键入大写“T”:

import Tkinter as tk

And to import "ttk",you can type this: 要导入“ttk”,您可以输入:

import ttk

It seems like it is no obvious defferrence of module tkinter in py2.x and py3.x,so just go ahead to use it!good luck! 好像在py2.x和py3.x中没有明显的模块tkinter,所以请继续使用它!祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM