Skip to content
Advertisement

unbound method mainloop() must be called with Tk instance as first argument (got nothing instead)

The below code is a simple code which I tried to check if Tkinter worked…

import Tkinter
top=Tkinter.Tk
top.mainloop()

Acoording to https://www.tutorialspoint.com/python/python_gui_programming.html

this should open a blank window

But the following error message was received

  File "b.py", line 3, in <module>
    top.mainloop()
TypeError: unbound method mainloop() must be called with Tk instance as first argument (got nothing instead)

Any suggestions…

Advertisement

Answer

Tkinter.Tk() creates an instance of Tk() object which act as argument for mainloop. Do this instead:

top = Tkinter.tk() //will open a pop up box
top.mainloop()

Read this for further understanding. tkinter-understanding mainloop

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement