简体   繁体   中英

Cannot import ttk in python tkinter

I am trying to import ttk from tkinter. I am following instructions from this website :

I am using Spyder on mac with OS Mojave, on Spyder, python version is 3.8.6 (according to sys.version)

My code is:

import tkinter as tk
from tkinter import ttk

I am getting the following error message:

runfile('/Users/Tom/untitled0.py', wdir='/Users/Tom')
Traceback (most recent call last):

  File "/Users/Tom/untitled0.py", line 3, in <module>
    from tkinter import ttk

ImportError: cannot import name 'ttk' from 'tkinter' (/Applications/Spyder.app/Contents/Resources/lib/python38.zip/tkinter/__init__.pyc)

You probably deleted all the contents of the ttk file. Uninstall and reinstall python and try again.

( Spyder maintainer here ) The problem happened because Tk was not included in our Mac application. However, that's fixed now in our 4.2.5 or any 5 versions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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