1

I am trying to run this code

from tkinter import *
master = Tk() 
w = Canvas(master, width=40, height=60) 
w.pack() 
canvas_height=20
canvas_width=200
y = int(canvas_height / 2) 
w.create_line(0, y, canvas_width, y ) 
mainloop()

and I get the error

Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'tkinter'

Since tkinter is already present in python, I checked in the C:\Python38\Lib\site-packages to see if tkinter is already present but its not there, also I tried the following

Running python -m tkinter from the command line should open a window demonstrating a simple Tk interface, letting you know that tkinter is properly installed on your system, and also showing what version of Tcl/Tk is installed, so you can read the Tcl/Tk documentation specific to that version

as mentioned on tkinter — Python interface to Tcl/Tk

I tried to install the tkinter using pip3 install tk , and I got Requirement already satisfied: tk in c:\python38\Lib\site-packages (0.1.0)

But when I run the code again I get the error

ERROR: Could not find a version that satisfies the requirement tkinter (from versions: none) ERROR: No matching distribution found for tkinter

My python version is Python 3.8.0 and pip version is pip 19.3.1

I have referred to this but no success.

Where am I going wrong? Please help

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Sachin Yadav
  • 748
  • 9
  • 28

1 Answers1

0

You may not have ticked tkinter during installation.

  • Download the latest version of python from python.org
  • Run the installer
  • Click modify
  • Select the Tk checkbox (and anything else you want)
  • And continue through the installation.

Done.

Stevo
  • 248
  • 4
  • 8