I'm writing a Python 3.6 script that works with Tkinter and an SQLite 3 database, but I get this error:
if "fImage" in globals() and not(fImage==None):
UnboundLocalError: local variable 'fImage' referenced before assignment
The interested code is this:
from tkinter import *
from ttk import *
from tkinter import Toplevel, Tk
import sqlite3 as sql
def Salvataggio(mode,nome,cognome,sitoweb,email,idx):
conn=sql.connect(os.path.join(path, fn_prof),isolation_level=None)
c=conn.cursor()
if mode=="add":
if "fImage" in globals() and not(fImage==None):
c.execute("INSERT INTO prof VALUES ('{}','{}','{}','{}','{}','{}')".format(len(prof.keys())+1,nome.get(),cognome.get(),fImage,sitoweb.get(),email.get()))
else:
c.execute("INSERT INTO prof VALUES ('{}','{}','{}','{}','{}','{}')".format(len(prof.keys())+1,nome.get(),cognome.get(),"",sitoweb.get(),email.get()))
del fImage
wa.destroy()
elif mode=="edit":
if "fImage" in globals() and not(fImage==None):
c.execute("""UPDATE prof
SET nome = '{}', cognome = '{}', imageURI='{}', web='{}', email='{}'
WHERE ID={}; """.format(nome.get(),cognome.get(),fImage,sitoweb.get(),email.get(),idx))
else:
c.execute("""UPDATE prof
SET nome = '{}', cognome = '{}', web='{}', email='{}'
WHERE ID={}; """.format(nome.get(),cognome.get(),sitoweb.get(),email.get(),idx))
del fImage
def selImmagine(bi):
if not("fImage" in globals()):
global fImage
fImage=askopenfilename(filetypes=[(_("File Immagini"),"*.jpg *.jpeg *.png *.bmp *.gif *.psd *.tif *.tiff *.xbm *.xpm *.pgm *.ppm")])
# other code...
Do you know how to solve this? The error results with the if and the elif in the salvataggio() function. Thanks