0

It seem like pip install tkinter has been renamed to pip install tk. But when I try to run it, this happens:

AttributeError: module 'tk' has no attribute 'Tk'

This is my Code:

import tk 
from tk import *

base = Tk()
## base = tk.Tk() does not work as well

Also, there is no file in my directory named tkinter or tk and on Tkinter page has no mention about the change. Is anyone facing the same issue?

Any help appreciated. Thanks in advance.

Mike
  • 56
  • 1
  • 9
  • 1
    Not sure what to install with `pip` (I used `apt`), but AFAIK the module is still called `tkinter`, so `from tkinter import *`. Which version are you using? – tobias_k Sep 06 '21 at 12:17

2 Answers2

2

You are confusing two different things tkinter built-in module and tk external module, second is TensorKit is a deep learning helper between Python and C++. You should do

from tkinter import *
base = Tk()

Consult linked docs if you want to know more

Daweo
  • 31,313
  • 3
  • 12
  • 25
  • It's not advised to use `from tkinter import *`. It's better to use `import tkinter as tk` – TheLizzard Sep 06 '21 at 12:41
  • @TheLizzard I lifted `from tkinter import *` verbatim from [python tkinter docs](https://docs.python.org/3/library/tkinter.html) – Daweo Sep 06 '21 at 12:43
  • @Daweo The docs actually use `import tkinter as tk` in the simple hello world example. Also please look at [this](https://stackoverflow.com/q/3615125/11106801) – TheLizzard Sep 06 '21 at 12:45
0

If you still have problems, one nasty corner case is if you call your file tkinter.py. It won't find the actual module with the same name.

Sridhar Sarnobat
  • 25,183
  • 12
  • 93
  • 106