CIA

mail@pastecode.io avatar
unknown
python
2 years ago
17 kB
2
Indexable
Never
from tkinter import * # FOR PYTHON'S GUI FRAME APPLICATION
import pygame # to run Audio files in the below code
import mysql.connector as sql # to connect sql server to the python
import random # used to generate random numbers between specified range in this code
from tkinter import messagebox 
import time # to display the real time clock timer by using strftime function.


con=sql.connect(host="Localhost",user="root",passwd="Flower@123",database="cia")
cur=con.cursor()
cur.execute("select * from login")

l1=[[00000000,"00000000","0000","000000","0"]]
for i in cur:
	if i in l1:
		pass
	else:
		l1.append(list(i))


# to set the position of the tkinter window on the screen
# 1) to the right edge(0,0)
# 2) to the left edge(-1,0)
# <tkinter_window_name>.geometry("width x height + absissca + ordinate")
root=Tk()
root.geometry("750x500+250+150")
root.title("C.I.A")
root.iconbitmap("logo_1.ico")
image_1=PhotoImage(file="code_bg.png")
label=Label(image=image_1)
label.grid(row=0,column=0)
image_2=PhotoImage(file="tick_final.png")
Cia_logo=PhotoImage(file="cia.png")
wood=PhotoImage(file="eye.png")
eagle=PhotoImage(file="eagle.png")
creators=PhotoImage(file="creaters.png")

def bg():
	global root
	pygame.mixer.init()
	pygame.mixer.music.load("MI.mp3")
	pygame.mixer.music.play(loops=10)

bg()

def register():
	def done():
		global l1
		global con
		global cur
		global button_rsubmit
		for j in l1:
						
			if j[2]==e_rcode.get():

				frame_gen=Frame(register,bg="#90EE90")
				frame_gen.place(x=0,y=0,width=200,height=200)
				label_gen=Label(frame_gen,text="the New ID\nis successfully generated\nnow you are a member!\n    \nyour'e ID is:"+str(id),fg="Blue",font=("consolas",10,"bold"),bg="#90EE90")
				label_gen.pack()
				break

			elif len(e_rcode.get())==0 or len(e_rname.get())==0 or len(e_rpasscode.get())==0 or len(e_rlevel.get())==0:
				print("all fields are required")
				break

			elif len(e_rcode.get())!=4:
				print("enter a 4 digit valid code")
				break

			
			else:
				id=random.randint(100000000,999999999)
				for l in l1:
					if l[0]==id:
						print("The ID is Already Exists\n your ID is:",l[0])
						break
					else:
						# METHOD to insert entry values into the SQL table.
						t2=(id,e_rname.get(),e_rcode.get(),e_rpasscode.get(),e_rlevel.get())
						sql="INSERT INTO login(ID,Agent_name,Agent_code,Agent_passcode,level) VALUES(%s,%s,%s,%s,%s)"
						cur.execute(sql,t2)
						con.commit() # to apply the changes done to the sql table
						frame_gen=Frame(register,bg="#90EE90")
						frame_gen.place(x=0,y=0,width=200,height=200)
						label_gen=Label(frame_gen,text="the New ID\nis successfully generated\nnow you are a member!\n    \nyour'e ID is:"+str(id),fg="Blue",font=("consolas",10,"bold"),bg="#90EE90")
						label_gen.pack()
						l1.append(list(t2))
				
				
				
						
						e_rname.delete(0,END)
						e_rcode.delete(0,END)
						e_rpasscode.delete(0,END)
						e_rlevel.delete(0,END)
						break
			
				
		
	# REGISTRATION ENTRY WINDOW
	register=Tk()
	register.geometry("200x200")
	register.title("RG")
	register.iconbitmap("register.ico")
	frame_r=Frame(register,bg="black")
	Label_r=Label(frame_r,text="Enter your details\n note:Registered accounts are\nnot taken",font=("consolas",10,"bold"),bg="black",fg="white")
	l_rname=Label(frame_r,text="NAME",font=("consolas",12,"bold"),bg="black",fg="white")
	e_rname=Entry(frame_r)
	l_rcode=Label(frame_r,text="CODE",font=("consolas",12,"bold"),bg="black",fg="white")
	e_rcode=Entry(frame_r,show="*")
	l_rpasscode=Label(frame_r,text="PASS",font=("consolas",12,"bold"),bg="black",fg="white")
	e_rpasscode=Entry(frame_r)
	l_rlevel=Label(frame_r,text="LEVEL",font=("consolas",12,"bold"),bg="black",fg="white")
	e_rlevel=Entry(frame_r)
	button_rsubmit=Button(frame_r,text="done",relief=RIDGE,command=done)
	#positioning system
	Label_r.pack()
	frame_r.place(x=0,y=0,width=200,height=200)
	l_rname.place(x=10,y=45)
	e_rname.place(x=60,y=50)
	l_rcode.place(x=10,y=75)
	e_rcode.place(x=60,y=80)
	l_rpasscode.place(x=10,y=105)
	e_rpasscode.place(x=60,y=110)
	l_rlevel.place(x=10,y=140)
	e_rlevel.place(x=60,y=140)
	button_rsubmit.place(x=150,y=170)
	register.mainloop()

def server():
	Frame_timeout=Frame(bg="black")
	Frame_timeout.place(x=0,y=0,width=750,height=500)
	label=Label(Frame_timeout,text="SERVER\n    TIMEOUT",font=("consolas",72,"bold"),bg="black",fg="red")
	label.place(x=20,y=50)
	root.after(3000,root.quit)

def play_alert():
	pygame.mixer.init()
	pygame.mixer.music.load("servertimeout.mp3")
	pygame.mixer.music.play(loops=0)
	if end():
		pygame.mixer.music.pause() # to stop the mp3 audio file.



def timer():
	root.after(95000,play_alert)
	root.after(117000,server)
	root.after(120000,root.quit)



def play():
	pygame.mixer.init()
	pygame.mixer.music.load("selfdestruct.mp3")
	pygame.mixer.music.play(loops=0)


def tryagain():
	mainframe()


def denied():
	pygame.mixer.init()
	frame_temp=Frame(bg="red")
	label_denied=Label(frame_temp,text="A C C E S S D E N I E D\n RECORD NOT FOUND!",font=("consolas",30,"bold"),fg="black",bg="Red")
	label_denied.place(x=100,y=200)
	frame_temp.place(x=0,y=0,width=750,height=500)
	def chance():
		button_Tryagain=Button(frame_temp,text="Tryagain",padx=10,pady=10,command=tryagain)
		button_Tryagain.place(x=330,y=400)
    # Buzzer mp3 audio	
	pygame.mixer.music.load("buzzer.mp3")
	pygame.mixer.music.play(loops=0)
	root.after(2000,chance)


def mainframe():
	# Mainframe_login

	frame_bg=Frame()
	frame_bg.place(x=0,y=0,width=750,height=500)
	label_bg=Label(frame_bg,image=image_1)
	label_bg.place(x=0,y=0,width=750,height=500)
	frame_1=LabelFrame(bg="Green",text="Login",font=("consolas",25))
	Label_title=Label(root,text="WELCOME TO THE C. I. A",font=("consolas",30,"bold"),bg="white")
	label_instructions=Label(frame_1,text=" C I A TERMINAL\n \n TOP SECRET | CONFIDENTIAL\n  \nLevel[5]-access to secret doc list\n \nlevels<5 ---only for personal targets\n \nunauthorised entry is strictly prohibited",bg="green",fg="yellow",font=("consolas",14,"bold"))
	label_instructions.place(x=80,y=0)
	l_code=Label(frame_1,text="Agent_Code",fg="white",font=("consolas",20,"bold"),bg="green")
	l_passcode=Label(frame_1,text="Passcode",fg="white",font=("consolas",20,"bold"),bg="green")
	e_code=Entry(frame_1,width=30,show="*")
	e_passcode=Entry(frame_1,width=30,show="*")
	frame_timer=Frame(root,bg="Blue")
	label_c=Label(frame_timer,text="Clock time",bg="blue",fg="white",font=("consolas",15,"bold"))
	label_timer=Label(frame_timer,text=" ",bg="blue",fg="white",font=("consolas",14,"bold"))# has been configured to clock
	l_default=Label(frame_1,text="The Server gets Timed out\n in next 120 seconds",font=("consolas",18,"bold"),bg="green",fg="blue")

	def clock():
		# make a real time clock
		hour=time.strftime("%I")
		minute=time.strftime("%M")
		second=time.strftime("%S")
		point=time.strftime("%p")
		label_timer.config(text=hour+":"+minute+":"+second+" "+point)
		root.after(1000,clock)

	def granted(j):
		frame_access=Frame(bg="Green")
		frame_access.place(x=0,y=0,width=750,height=500)
		label_access=Label(frame_access,text="A C C E S S G R A N T E D",font=("consolas",30,"bold"),fg="black",bg="Green")
		label_access.place(x=100,y=200)
		label_welcome=Label(frame_access,text=j[1].upper()+"-level="+str(j[4]),fg="White",font=("consolas",30),bg="Green")
		label_welcome.place(x=100,y=300)
		e_code.delete(0,END)
		e_passcode.delete(0,END)
		button_proceed=Button(frame_access,text="PROCEED",relief=RAISED,bg="yellow",padx=10,pady=10,command=proceed)
		button_proceed.place(x=375,y=400)

	
	def check():
		global l1
		global cur
		global con
		code_check=e_code.get()
		passcode_check=e_passcode.get()


		for k in l1:

			if len(code_check)==0 or len(passcode_check)==0:

				print("ALL FIELDS ARE REQUIRED !")
				
				break

			elif str(k[3])==passcode_check and str(k[2])==code_check:
				granted(k)
				
				
				break

			elif str(k[3])!=passcode_check or str(k[2])!=code_check:
				denied()

		

	# positioning system
	label_c.pack()
	frame_timer.place(x=627,y=5,width=120,height=70)
	label_timer.place(x=0,y=30)
	Label_title.grid(row=0,column=0,sticky=N)
	l_code.place(x=50,y=200)
	l_passcode.place(x=50,y=250)
	e_code.place(x=230,y=210)
	e_passcode.place(x=230,y=260)
	frame_1.place(x=80,y=80,width=600,height=400)
	l_default.place(x=120,y=300)

	# CLOCK TIME.
	clock()

	#Timeout

	timer()

	# LOGIN BUTTONS
	Button_submit=Button(frame_1,text="submit",borderwidth=5,relief=RAISED,state=ACTIVE,command=check)
	Button_submit.place(x=500,y=300)
	# EXIT BUTTON
	button_exit=Button(frame_1,text="exit",borderwidth=5,relief=RAISED,command=root.quit)
	button_exit.place(x=30,y=300)

def look():
	look=Tk()
	look.geometry("250x250+320+400")
	look.configure(bg="Green")
	img_1=PhotoImage(file="img1.png",master=look)
	img_2=PhotoImage(file="img2.png",master=look)
	img_3=PhotoImage(file="img3.png",master=look)
	img_4=PhotoImage(file="img4.png",master=look)
	img_5=PhotoImage(file="img5.png",master=look)
	img_6=PhotoImage(file="img6.png",master=look)
	img_7=PhotoImage(file="img7.png",master=look)
	img_8=PhotoImage(file="img8.png",master=look)
	img_9=PhotoImage(file="img9.png",master=look)
	img_10=PhotoImage(file="img10.png",master=look)
	img_11=PhotoImage(file="img11.png",master=look)
	img_12=PhotoImage(file="img12.png",master=look)
	img_list=[img_1,img_2,img_3,img_4,img_5,img_6,img_7,img_8,img_9,img_10,img_11,img_12]
	label_1=Label(look,image=img_1)
	label_1.pack()
	image_number=0
			
	def forward():
		#label_1.grid_forget()
		nonlocal image_number
		if image_number==11:
			print("OUT OF RANGE--->")
		else:
			my_label=Label(look,image=img_list[image_number+1])
			my_label.place(x=30,y=0)
			image_number+=1
			print(image_number)
		
	def back():
		nonlocal image_number # we use the nonlocal keyword to access the variables defined inside a f'n for nested functions,by declaring it as nonlocal to the inner ones.
		if image_number==0:
			print(" OUT OF RANGE<---")
		else:
			my_label=Label(look,image=img_list[image_number-1])
			my_label.place(x=30,y=0)
			image_number-=1
			print(image_number)

	button_forward=Button(look,text=">>>",padx=5,pady=5,bg="black",fg="white",command=forward) # we use lambda method to pass values in a function through command parameter.
	button_back=Button(look,text="<<<",padx=5,pady=5,bg="black",fg="white",command=back)
	#button_exit=Button(look,text="Exit Program",padx=5,pady=5,relief=RAISED,command=look.quit)
	#button_exit.pack(side=BOTTOM)
	button_forward.place(x=200,y=220)
	button_back.place(x=5,y=220)
	look.mainloop()
	if end()==True:
		look.quit()


def imageviewer():

	viewer=Tk()
	viewer.geometry("330x480+400+150")
	def clist():
		frame_clist=Frame(viewer,bg="brown")
		frame_clist.place(x=0,y=0,width=350,height=480)
		box2=Text(frame_clist,width=40,height=25,padx=2)
		box2.place(x=0,y=10)
		f=open("confidential.txt",'r')
		aaa=f.read()
		# put the file content in the text box
		box2.insert(END,aaa)

		def save():
			f_save=open("confidential.txt","w")
			f_save.write(box2.get(1.0,END))

		button_save=Button(frame_clist,text="UPDATE",padx=10,pady=5,bg="green",fg="white",font=("consolas",15,"bold"),relief=RAISED,command=save)
		button_save.place(x=160,y=420)

	greeny=PhotoImage(file="greeny.png",master=viewer)
	label_greeny=Label(viewer,image=greeny)
	label_greeny.place(x=0,y=2)
	ncr_image=PhotoImage(file="crime record logo.png",master=viewer)
	label_NCR=Label(viewer,image=ncr_image)
	label_NCR.place(x=45,y=20)
	button_check=Button(viewer,text="check the criminal\n details",padx=10,pady=10,relief=RIDGE,command=clist,font=("consolas",15,"bold"),fg="white",bg="black")
	button_check.place(x=40,y=270)

	viewer.mainloop()
	if end()==True:
		viewer.quit()

def proceed():
	# Access terminal interface.
	global doc_list
	global wood
	frame_target=Frame()
	frame_target.place(x=0,y=0,width=750,height=500)
	l_target=Label(frame_target,image=wood)
	l_target.place(x=0,y=0,width=750,height=500)
	frame_lset=LabelFrame(frame_target,text="SET TARGET",font=("consolas",20,"bold"),bg="Red")
	frame_lset.place(x=400,y=50,width=300,height=150)
	# doc list frame
	frame_list=LabelFrame(frame_target,text="TOP 10 MOST WANTED",font=("consolas",20,"bold"),bg="blue",fg="white")
	frame_list.place(x=400,y=250,width=300,height=150)
	button_list=Button(frame_list,text="Expanded View",padx=5,pady=5,bg="white",fg="black",command=doc_list)
	button_list.pack()
	
	button_look=Button(frame_target,text="Click the button\nto View the images",font=("consolas",18,"bold"),padx=5,pady=5,fg="white",bg="Black",command=look)
	button_look.place(x=90,y=250)


	#eliminate targets
	list_target=[]
	clicked=StringVar()
	cur.execute("select * from criminal")
	for i in cur:
		if i in list_target:
			pass
		else:
			list_target.append(str(i[1]).strip("['']"))

	print(list_target)

	def eliminate():
		#l_temp=list(clicked.get())
		list_target.remove(clicked.get())
		cur.execute("DELETE from criminal where name='{}'".format(clicked.get()))
		con.commit()
		messagebox.showinfo("right","TARGET ELIMINATED FROM THE DATABASE")


	def end():
		
		def bye():
			frame_bye=Frame(frame_end,bg="blue")
			frame_bye.place(x=0,y=0,width=750,height=500)
			label_bye=Label(frame_bye,text="You have logged out successfully!\n BYE!๐Ÿ‘( อกโ›โ€ฏอœส– อกโ›)๐Ÿ‘ ",bg="blue",font=("consolas",30,"bold"),fg="Yellow")
			label_bye.pack()
	

		def logout():
			button_exit=Button(frame_end,text="E X I T",padx=5,pady=3,font=("consolas",30,"bold"),command=bye)
			button_exit.place(x=300,y=400)
		
		# ending frame
		frame_end=Frame(bg="Blue")
		frame_end.place(x=0,y=0,width=750,height=500)
		play()
		root.after(5000,logout)
		root.after(19500,quit)

	# set target drop down menu.
			
	drop_set=OptionMenu(frame_lset,clicked,*list_target)
	drop_set.place(x=100,y=30)
	button_eliminate=Button(frame_lset,text="eliminate",bg="black",fg="white",font=("consolas",10,"bold"),command=eliminate)
	button_eliminate.place(x=100,y=80)

	button_kill=Button(frame_target,text="KILL",font=("consolas",25,"bold"),bg="red",command=end)
	button_kill.place(x=350,y=430)
	button_see=Button(frame_target,text="CRIMINAL LIST",padx=10,pady=5,bg="Red",font=("consolas",20,"bold"),relief=RAISED,command=imageviewer)
	button_see.place(x=90,y=100)

def doc_list():
	doc_list=Tk()
	#text=""
	doc_list.title("doc list")
	doc_list.geometry("375x500+1000+150")
	#TOP 10 MOST WANTED
	top=PhotoImage(file="top10.png",master=doc_list) # the "MASTER " parameter will shift the image's main instance to specified window.
	label_mw=Label(doc_list,image=top)
	label_mw.pack()
	#label=Label(doc_list,text=text,fg="green",bg="black",font=("consolas",20,"bold"))
	#label.pack()
	#doc_list.overrideredirect(1)
	Button_expand=Button(doc_list,text="CHECK THE DETAILS",padx=10,pady=10,relief=RAISED,command=mw_list)
	Button_expand.place(x=120,y=300)
	doc_list.mainloop()

	if root.quit()==True:
		doc_list.quit()


def mw_list():
	mw_list=Tk()
	mw_list.geometry("375x500+1000+150")
	f1=open("Mostwanted.txt","r")
	mw_read=f1.read()
	box1=Text(mw_list,width=40,height=25,padx=2)
	box1.pack()
	def save():
		f_save=open("Mostwanted.txt","w")
		f_save.write(box1.get(1.0,END))
	
	button_save=Button(mw_list,text="UPDATE",padx=10,pady=5,bg="green",fg="white",font=("consolas",15,"bold"),relief=RAISED,command=save)
	button_save.place(x=140,y=400)
	
	box1.insert(END,mw_read)
	if end()==True:
		mw_list.quit()


#user registration.
frame_0=Frame(root,bg="Blue")
frame_0.place(x=0,y=0,width=750,height=500)
label_0=Label(frame_0,text="  || CENTRAL INTELLIGENCE AGENCY || \n \n  AGENT REGISTRATION AND LOGIN PORTAL",fg="cyan",bg="Blue",font=("consolas",25,"bold"))
label_0.place(x=20,y=5)
frame_l0=LabelFrame(frame_0,text="Validate your ID",fg="black",bg="red",font=("consolas",15))
frame_l0.place(x=20,y=180,width=300,height=105)
label_exist=Label(frame_0,text="   --->Login as an existing Agent",fg="white",bg="blue",font=("consolas",18))
label_exist.place(x=300,y=350)
button_existing=Button(frame_0,text="L O G I N",padx=60,pady=30,bg="green",fg="white",command=mainframe)
button_existing.place(x=450,y=400)
button_quit=Button(frame_0,text="exit",relief=RAISED,command=root.quit)
button_quit.place(x=700,y=450)
label_eagle=Label(frame_0,image=eagle)
label_eagle.place(x=170,y=330)
label_img=Label(frame_0,image=Cia_logo)
label_img.place(x=10,y=330)
label_creator=Label(frame_0,image=creators)
label_creator.place(x=330,y=120)
button_register=Button(frame_l0,text="REGISTER HERE",padx=60,pady=20,command=register)
button_register.place(x=10,y=10)
root.overrideredirect(1) # to disable top level window & buttons.
root.mainloop()