Jul-15-2019, 05:04 PM
I am trying to use a global variable which is then incremented in a function but I am getting this error:
File "E:\Python 3\Prehistoric Life\prehistoricLife.py", line 169, in fetchRecord recNo += 1
UnboundLocalError: local variable 'recNo' referenced before assignment.
It is saying that recNo is a local variable.
Here is an excerpt of the code where I set recNo as a global and then the function where I am using it.
File "E:\Python 3\Prehistoric Life\prehistoricLife.py", line 169, in fetchRecord recNo += 1
UnboundLocalError: local variable 'recNo' referenced before assignment.
It is saying that recNo is a local variable.
Here is an excerpt of the code where I set recNo as a global and then the function where I am using it.
from tkinter import *
from tkinter import ttk
import sqlite3
root = Tk()
#---------------------------[ Global Variables ]--------------------------------
dinoPath = 'dino_images\\'
sizePath = 'dinosize\\'
maxRec = 0
recNo = 0
rowCount = 0
#---------------------------- Clear all entry boxes ---------------------------------
def fetchRecord():
recBox.delete(0,END) #entry boxes
eName.delete(0,END)
eMeaning.delete(0,END)
ePronounce.delete(0,END)
ePeriod.delete(0,END)
eGroup.delete(0,END)
eSize.delete(0,END)
eLived.delete(0,END)
eDiet.delete(0,END)
eFossils.delete(0,END)
factFile.delete(1.0,END) #Textbox
#---------------------------- Get Record From Database ---------------------------------
recNo += 1 #increment recNo
conn=sqlite3.connect('dinobase.db')
c=conn.cursor()
c.execute('SELECT * FROM dino WHERE record = recNo')
rows=c.fetchall()
for row in rows:
recBox.insert(0,row[0])
eName.insert(0,row[1])
eMeaning.insert(0,row[2])
ePronounce.insert(0,row[3])
ePeriod.insert(0,row[4])
eGroup.insert(0,row[5])
eSize.insert(0,row[6])
eLived.insert(0,row[7])
eDiet.insert(0,row[8])
eFossils.insert(0,row[9])
factFile.insert(1.0,row[10])
c.close()
conn.close()Any suggestions appreciated.
