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

时间:2022-05-02 01:21:36

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. Why is that?

当我输入Tkinter import ttk时,它说没有名为ttk的模块,而且在许多在线网站上,Tkinter中的t总是小写的,但是当我在Python中输入Tkinter时,它会抛出一个错误。这是为什么呢?

4 个解决方案

#1


11  

Tkinter in python 2.6 is capitalized, in python 3 it is lowercase, tkinter

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

#2


9  

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中的Tkinter。在Python 3中的x和tkinter。x版本。

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。您将导入ttk as

from Tkinter import *
import ttk

And in Python 3.x you would import ttk as

Python 3。您将导入ttk as

from tkinter import *
from tkinter.ttk import *

or

from tkinter import ttk

#3


4  

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. 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!

Python是区分大小写的(就像大多数编程语言一样),但是“许多网站”却不是(像大多数人一样),所以在“许多网站”的部分拼错Tkinter是完全可以理解的。嘿,你自己用小写开头的句子打破了英语规则,在你的简短问题中两次,你应该同情在那些“很多网站”中使用错误的大小写,而且绝对不应该对此感到惊讶!

#4


0  

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中似乎没有明显的模块tkinter的错误。x和py3。x,那就用它吧!好运!

#1


11  

Tkinter in python 2.6 is capitalized, in python 3 it is lowercase, tkinter

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

#2


9  

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中的Tkinter。在Python 3中的x和tkinter。x版本。

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。您将导入ttk as

from Tkinter import *
import ttk

And in Python 3.x you would import ttk as

Python 3。您将导入ttk as

from tkinter import *
from tkinter.ttk import *

or

from tkinter import ttk

#3


4  

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. 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!

Python是区分大小写的(就像大多数编程语言一样),但是“许多网站”却不是(像大多数人一样),所以在“许多网站”的部分拼错Tkinter是完全可以理解的。嘿,你自己用小写开头的句子打破了英语规则,在你的简短问题中两次,你应该同情在那些“很多网站”中使用错误的大小写,而且绝对不应该对此感到惊讶!

#4


0  

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中似乎没有明显的模块tkinter的错误。x和py3。x,那就用它吧!好运!