pythonpython-3.xtkintertkmessagebox

Python and tkinter: NameError: name 'askyesno' is not defined


I get this error:

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python36-32\lib\tkinter\__init__.py", line 1699, in __call__ return self.func(*args)
File "C:\Users\Administrator\Desktop\Base\utility.py", line 68, in clear
askyesno('Clear', 'Press YES or NO')
NameError: name 'askyesno' is not defined

When I try to run this:

if askyesno('Clear', 'Press YES or NO'):
 do some code

I have tried tkMessageBox.askyesno but still getting the error.


Solution

  • Try this from tkinter import messagebox to import messagebox and then:

     if messagebox.askyesno('Clear', 'Press YES or NO'):