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 in Python by Aman
632 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 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 by rahul
• 200 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 in Python by Noel Deepak Palle
482 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 in Python by Greg
682 views
0 votes
0 answers

How to solve the error - ssl module not found?

I am getting this error while trying ...READ MORE

Aug 8 in Python by Waseem
• 4,470 points
40 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 in Python by Icetutor
• 160 points
603 views
0 votes
1 answer
0 votes
1 answer

Python argparse error "NameError: name 'file' is not defined"

The right datatype for destination in argpasrse module ...READ MORE

answered Nov 28, 2018 in Python by Omkar
• 67,660 points
1,887 views
+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 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 351 views
+4 votes
6 answers