Tkinter module not callable error

0 votes

Hi. I am trying to write a python code with tkinter. This is my code:

import Tkinter as Tk

root = Tk()

And I am getting this error:

root = Tk()

TypeError: 'module' object is not callable

How to solve this?

May 8, 2019 in Python by Aman
14,907 views

2 answers to this question.

0 votes

Tk() is a module and not a method. You have to call the Tk() method from the tkinter module. Try this:

import Tkinter as tk
root = tk.Tk()

This should work

answered May 8, 2019 by Yash
+1 vote

This error statement TypeError: 'module' object is not callable is raised as you are being confused about the Class name and Module name. The problem is in the import line. You are importing a module, not a class. This happened because the module name and class name have the same name.

If you have a class "MyClass" in a file called "MyClass.py", then you should import :

from MyClass import MyClass

In Python, a script is a module, whose name is determined by the filename. So when you start out your file MyClass.py with import MyClass you are creating a loop in the module structure.

In Python, everything (including functions, methods, modules, classes etc.) is an object, and methods are just attributes like every other. So, there are no separate namespaces for methods. So when you set an instance attribute, it shadows the class attribute by the same name. The obvious solution is to give attributes of different names.

answered Jun 27, 2019 by rahul
• 360 points
Thanks for the explanation.

Related Questions In Python

0 votes
1 answer

i am normalizing the data set iris in python and get the error ::TypeError: 'numpy.float64' object is not callable

TRY THIS   #Nomalisation for i in names:     print(i)   ...READ MORE

answered Aug 19, 2019 in Python by Noel Deepak Palle
4,289 views
0 votes
1 answer

Python error "'Series' object is not callable "

Try this: df['ln_returns'] = np.log(df['Close_mid']/df['Close_mid']) df['Close_mid'](1)) doesn't seem to ...READ MORE

answered Jul 22, 2019 in Python by Greg
12,505 views
0 votes
2 answers

How to solve the error - ssl module not found?

Hey, @There, nstall the necessary packages for Python ...READ MORE

answered Oct 23, 2020 in Python by Gitika
• 65,870 points
743 views
0 votes
2 answers

Python error "ImportError: No module named 'tkinter'"

sudo apt-get install python3-tk Then, >> import tkinter # ...READ MORE

answered Nov 9, 2019 in Python by Icetutor
• 160 points
15,548 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,969 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
1,504 views
0 votes
3 answers

Python error "NameError: name 'sr' is not defined"

NameError: name 'xx' is not defined Python knows ...READ MORE

answered Mar 19, 2020 in Python by rahul
• 360 points
32,628 views
0 votes
3 answers

How to use not equal operator in python

We can use Python not equal operator ...READ MORE

answered Dec 9, 2020 in Python by Niroj
• 82,680 points
122,463 views