Home > Net >  I'm trying to make an exit button for the page and for some reason it has error and i don'
I'm trying to make an exit button for the page and for some reason it has error and i don'

Time:01-30

I am trying to make an exit button with the code I do import tkinter* in here

from tkinter import*
from tkinter import ttk
from PIL import Image,ImageTk
import os

def iExit(self):
        self.iExit=tkinter.askyesno("Face Recognition","Are you sure you want to exit?")
        if self.iExit >0:
            self.root.destroy()
        else:
            return 

and I got the error

I know that I cant put tkinter inside the code but i don't know how to solve it. The error that I am getting is here

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\tkinter\__init__.py", line 1948, in __call__
    return self.func(*args)
           ^^^^^^^^^^^^^^^^
  File "c:\Users\user\Desktop\FYP\Facial_Recognition system\Main.py", line 148, in iExit
    self.iExit=tkinter.askyesno("Face Recognition","Are you sure you want to exit?")
               ^^^^^^^
NameError: name 'tkinter' is not defined

CodePudding user response:

askyesno is defined in the tkinter.messagebox module. Import it from there:

from tkinter.messagebox import askyesno
  • Related