Good day to everyone. I need help with my python program. I am almost done making a police profile system wherein you can input and search. The problem I have is in the search function. Here is the bit of the source code to get started.
global Value
def config1():
Entry1.config(state="normal")
Entry1.delete(first=0,last=99)
Entry1.insert(0,"LastName")
Entry1.config(state="disabled")
ThisEntry.delete(first=0,last=99)
Value = Police['text']
def config5():
Entry1.config(state="normal")
Entry1.delete(first=0,last=99)
Entry1.insert(0,"LastName")
Entry1.config(state="disabled")
ThisEntry.delete(first=0,last=99)
Value = Visitor['text']
def Search():
Entry1.config(state="normal")
x = Entry1.get()
y = ThisEntry.get()
Entry1.config(state="disabled")
global Value
if x == "LastName" and Value == "POLICE IDENTITY":
z = 0
ThisText.config(state="normal")
ThisText.delete("1.0","end")
c.execute("SELECT LastName FROM Police WHERELastName=?",(y,))
row = c.fetchall()
for a in row:
c.execute("SELECT * FROM Police WHERE LastName=?",(y,))
row = c.fetchall()
elif x == "LastName" and Value == "VISITOR":
z = 0
ThisText.config(state="normal")
ThisText.delete("1.0","end")
ThisText.insert(INSERT,"VISITORS")
c.execute("SELECT LastName FROM Visitors WHERE LastName=?",(y,))
row = c.fetchall()
for a in row:
ThisText.insert(INSERT,"\n\n")
ThisText.insert(INSERT,"Visitor Number: ")
ThisText.insert(INSERT,row[z][0])
ThisText.insert(INSERT,"\n")
ThisText.insert(INSERT,"First Name: ")
ThisText.insert(INSERT,row[z][1])
ThisText.insert(INSERT,"\n")
ThisText.insert(INSERT,"Middle: ")
ThisText.insert(INSERT,row[z][2])
ThisText.insert(INSERT,"\n")
ThisText.insert(INSERT,"Last Name: ")
I used the functions def config1():
and def config5():
just to change the value of the Value
. I declared the Value
as global
since I need it just for changing the value.
The main goal is that the condition will return a row if the value is equal to the record that I want to search and if it is equal to the type of record that I want to search which is the Value
.
So if I search for the LastName
in Police Identity, it would return a row. Same with searching for Visitor.
If I search for the last name in the Police Identity Tab, it returns a row properly. But whenever I try to search for the last name in the Visitor Tab, it returns this error:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 1550, in __call__
return self.func(*args)
File "C:\Users\User\Desktop\School Files (Don't Touch)\Project in SE\Project in SE.py", line 1420, in Search
elif x == "LastName" and Value == "POLICE IDENTITY":
NameError: name 'Value' is not defined
I tried to declare the global variable on the function itself also but it still doesn't work. I really don't get why it works on one condition but doesn't work on the other condition. I don't know if Python is playing a game on me or something. Btw I don't think there are any duplicates for this question.