I’m following a simple tutorial, learning about the tkinter library. In the tutorial, they do this:
JavaScript
x
3
1
from tkinter import *
2
from tkinter import ttk
3
I was told the above is not good practice so instead I did:
JavaScript
1
2
1
import tkinter as tk
2
However, later on in the code I have to do something like this:
JavaScript
1
2
1
mainframe = ttk.Frame(root, padding="3 3 12 12")
2
This gives me an error because I didn’t import ttk
as its own module. I would assume something like this should work:
JavaScript
1
2
1
mainframe = tk.ttk.Frame(root, padding="3 3 12 12")
2
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
JavaScript
1
2
1
import tkinter.ttk as tkk
2