I’m following a simple tutorial, learning about the tkinter library. In the tutorial, they do this:
from tkinter import * from tkinter import ttk
I was told the above is not good practice so instead I did:
import tkinter as tk
However, later on in the code I have to do something like this:
mainframe = ttk.Frame(root, padding="3 3 12 12")
This gives me an error because I didn’t import ttk as its own module. I would assume something like this should work:
mainframe = tk.ttk.Frame(root, padding="3 3 12 12")
yet it also gives me an error. How do I access the ttk module if tk.ttk.Frame is not the way to do it?
Advertisement
Answer
ttk is not a part of the tkinter module, it is a different file in the tkinter.
In order to import ttk you have to do this
import tkinter.ttk as tkk