When you do import tkinter
, then you must prefix all tkinter commands and constants with tkinter.
(eg: buttontkinter.Button(...)
, root=tkinter.Tk()
, etc).
When you do from tkinter import *
, it imports everything that tkinter has marked as exportable, and you do not prefix things with tkinter.
(eg: button=Button(...)
, root=Tk()
, etc)
You should do one or the other, not both. Preferably, do the former. To make for a little less typing you can import with an alias, for example:
import tkinter as tk
...
root = tk.Tk()
button = tk.Button(root, ...)
Note that this isn't a tkinter-specific problem. This is fundamentally how importing all modules in python works.
Also note that, while ttk
is in tkinter
, it doesn't get imported when you do from tkinter import *
. Also, ttk will export classes with the same name as tkinter (for example: they both define Button
)
For more information, read the documentation on modules in the python documentation. You might also want to read the answers to ImportError when importing Tkinter in Python