I'm a beginner, and from my first steps, I have a strange problem. No matter what I have done (google it, set a virtual environment, reinstalling the language several times, installing deferent versions of the language) when I'm trying to give the code:
from future.moves import Tkinter as tk
window = tk.tk()
# to rename the title of the window
window.title("GUI")
# pack is used to show the object in the window
label = tk.label(window, text = "Welcome to DataCamp's Tutorial on Tkinter!").pack()
It gives me the following error:
Error:
Traceback (most recent call last):
File "D:/Applications/Python 3.7.2/Scripts/Modules-and-Functions-in-Python-Introduction-to-Tkinter-Source-code/sowtest.py", line 1, in <module>
from future.moves import Tkinter as tk
File "C:\Users\Αλέκος Βαγιώνης\venv\python 3.7\lib\site-packages\future\moves\tkinter\__init__.py", line 27, in <module>
from Tkinter import *
ModuleNotFoundError: No module named 'Tkinter'
Process finished with exit code 1
All that, after I have tried with pip in the CMD to install the module.
Though it is included with Python (as I know)
I am running a Windows 10 tablet and I have the 3.7.3 version of Python.
(Jun-30-2020, 07:57 AM)All_ex_Under Wrote: [ -> ]from future.moves import Tkinter as tk
window = tk.tk()
# to rename the title of the window
window.title("GUI")
# pack is used to show the object in the window
label = tk.label(window, text = "Welcome to DataCamp's Tutorial on Tkinter!").pack()
Have you tried
from future.moves import tkinter as tk
window = tk.Tk()
as capitalization matters, I tried that with tkinter and works just fine (well it does load the library)
for example after you set tkinter you will get an error for your tk.tk() as it should be tk.TK() the same goes for label, it should be Label
so it should be
from future.moves import tkinter as tk
window = tk.Tk()
# to rename the title of the window
window.title("GUI")
# pack is used to show the object in the window
label = tk.Label(window, text = "Welcome to DataCamp's Tutorial on Tkinter!").pack()
@
jdos, your solution gives an excellent explanation, but the real problem is that he doesn't have the Tkinter module installed.
To do so, just go through
this link and proceed with the installation, depending upon your operating system/
In the first time, I installed it in D drive, now besides I reinstalled my python in my C drive (during the installation some shadows were telling me that some packages won`t be installed)but IntelliJ keeps looking at D:, it still gives me an error:
Error:
"C:\Users\Αλέκος Βαγιώνης\venv\python 3.7\Scripts\python.exe" "C:/Users/Αλέκος Βαγιώνης/venv/python 3.7/tesrtk.py"
No Python at 'D:\Applications\Python 3.7.2\python.exe'
Process finished with exit code 103
On the other side, it is still not recognizing the "Tkinter" module :
import TKinter
Telling me that the module still doesn`t exist.
(Jun-30-2020, 01:42 PM)All_ex_Under Wrote: [ -> ]In the first time, I installed it in D drive, now besides I reinstalled my python in my C drive (during the installation some shadows were telling me that some packages won`t be installed)but IntelliJ keeps looking at D:, it still gives me an error:
Error:
"C:\Users\Αλέκος Βαγιώνης\venv\python 3.7\Scripts\python.exe" "C:/Users/Αλέκος Βαγιώνης/venv/python 3.7/tesrtk.py"
No Python at 'D:\Applications\Python 3.7.2\python.exe'
Process finished with exit code 103
On the other side, it is still not recognizing the "Tkinter" module :
import TKinter
Telling me that the module still doesn`t exist.
Did you update your Python path with the latest one? And map your current Python path to the editor as well. Try running PIP command from the latest path
Have u named your py file tkinter.py? If so u should rename it, thats how I was able to solve the problem.
No need to use
future.moves
and as posted you most use
import tkinter
for Python 3.
Not
import Tkinter
(Is for the dead Python 2).
you see this clearly on doc to
A Simple Hello World Program.
First why don't you install v3.8? Second, if you have problems with the path, uninstall all versions, reboot, install new version.
When you start the installer be sure to check the auto path install.
After that locate your python (usually C:\Users\user\AppData\Local\Programs\Python\Python38-32\Scripts\) start cmd as administrator, cd to that folder and then run 'pip install tkinter' and all the other modules and libraries that you need.
Open IDLE and start coding.
And always remember, Capitalization matters. Tkinter is not tkinter for v3. 'label' is not 'Label' and tk.tk() is not tk.Tk(), that is to help you out of trouble. If you need help with the commands check
TkDocs.
Cheers!
Thank you all, Im thinking to go with Jdos suggestion, in fact I
ve already solved the issue with the path through running my system as administrator.