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
196 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
0 answers

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

for i in cnames:     print(i)     df_csv[i] = (df_csv[i] - ...READ MORE

Jul 14 in Python by anonymous
17 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 1 day ago in Python by Greg
4 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,160 points
981 views
0 votes
2 answers
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 in Python by Neha
• 330 points

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