Reputation: 3
I need Tkinter to use in one of my projects as a button etc. i pip installed Tkinter with the code below as i followed a tutorial online and it said to
pip install tk
is this not correct as when I import Tkinter import Tkinter
. it says module not found?
I have tried to restart my project and have tried every possible pip install combination ever.
Please help explain Tia.
Upvotes: 0
Views: 3657
Reputation: 1
For me, it depended on what version of python I was using. When I was trying to do turtle graphics for the first time, my Tkinter module wasn't importing. After from tkinter import Tk
, it worked. When we moved to python 3.8.5, it clearly had tkinter built into python 3 already, so try pip installing (just in case), then try from tkinter import Tk
again. If it isnt working, check to make sure that you're on the latest version of python!
Upvotes: 0
Reputation:
If you are using Python 3, Tkinter is built in. But you have to use a lowercase letter. Don't use "Tkinter", use "tkinter" instead.
Also, don't use "import tkinter", use "from tkinter import *", to import everything.
Example:
from tkinter import *
def command():
print("Hello, world!")
root = Tk()
root.title("tkWindow")
btn = Button(root, text="Click Me!", command=command)
btn.pack()
root.mainloop()
Also, remember that when you import everything from Tkinter (using from tkinter import *), you don't use tk.Tk() or tk.Button(), you just have to use Tk() and Button().
This should work for you. Good luck, and happy coding!
Upvotes: 2