Commit 73abbefa authored by charley.punshon's avatar charley.punshon

Update main.py

parent 5a6beac8
import base64
from tkinter import *
from tkinter.ttk import *
from urllib.request import urlopen
import urllib3
import json
......@@ -10,6 +8,7 @@ window = Tk()
width = window.winfo_screenwidth()
height = window.winfo_screenheight()
canvasmain = Canvas(window, width=f'{width / 2}', height=f'{height * 4}', bg='#cae8dc')
scrollbar = Scrollbar(window, orient="vertical", command=canvasmain.yview)
def login():
......@@ -42,54 +41,62 @@ def logout():
canvastitle.create_window(550, 170, window=password)
loginBtn = Button(window, text="Login", command=login)
loginBtn.pack(pady=10)
loginBtn_window = canvastitle.create_window(450, 190, anchor=NW, window=loginBtn)
canvastitle.create_window(450, 190, anchor=NW, window=loginBtn)
def menu():
canvasmain.create_text(500, 75, fill="black", font="Arial 40 bold", text="Select an option")
canvasmain.delete("all")
canvasmain.create_text(1000, 75, fill="black", font="Arial 40 bold", text="Select an option")
# Dog Breed Info Button
dogBreedInfoBtn = Button(window, text="Get Dog Breed Information", width=30, command=getDogs)
dogBreedInfoBtn.pack(pady=20)
canvasmain.create_window(400, 150, anchor=NW, window=dogBreedInfoBtn)
canvasmain.create_window(900, 150, anchor=NW, window=dogBreedInfoBtn)
# Add Dog Breed Button
dogBreedAddBtn = Button(window, text="Add Dog Breed", width=30, command=addDogCanvasUpdate)
dogBreedAddBtn.pack(pady=20)
canvasmain.create_window(400, 200, anchor=NW, window=dogBreedAddBtn)
canvasmain.create_window(900, 200, anchor=NW, window=dogBreedAddBtn)
# Delete Dog Breed Button
dogBreedDeleteBtn = Button(window, text="Delete Dog Breed", width=30, command=getDogsForDelete)
dogBreedDeleteBtn.pack(pady=20)
canvasmain.create_window(400, 250, anchor=NW, window=dogBreedDeleteBtn)
canvasmain.create_window(900, 250, anchor=NW, window=dogBreedDeleteBtn)
# Update Dog Breed Button
dogBreedUpdateBtn = Button(window, text="Update Dog Image", width=30, command=updateDogCanvasUpdate)
dogBreedUpdateBtn.pack(pady=20)
canvasmain.create_window(400, 300, anchor=NW, window=dogBreedUpdateBtn)
canvasmain.pack(pady=20)
canvasmain.create_window(900, 300, anchor=NW, window=dogBreedUpdateBtn)
canvasmain.pack(fill='both', pady=20)
def getDogs():
t = urllib3.PoolManager()
response = t.request('GET', "http://cs2s.yorkdc.net:5002/dogs")
if response.status == 200:
scrollbar.destroy()
canvasmain.delete("all")
canvasmain.create_text(500, 75, fill="black", font="Arial 40 bold", text="Dog Breed Information")
canvasmain.create_text(900, 75, fill="black", font="Arial 40 bold", text="Dog Breed Information")
scrollbar = Scrollbar(window, orient="vertical", command=canvasmain.yview)
dogs = json.loads(response.data)
column = 350
column = 900
row = 125
for x in dogs:
canvasmain.create_text(column, row + 25, fill="black", font="Arial 11 bold", text="Dog Breed: ")
canvasmain.create_text(column + 150, row + 25, fill="black", font="Arial 11 bold", text=x["dogbreed"])
canvasmain.create_text(column - 50, row + 50, fill="black", font="Arial 11 bold",
text="Minimum Exercise Per Day: ")
canvasmain.create_text(500, row + 50, fill="black", font="Arial 11 bold", text=x["exercise"])
canvasmain.create_text(1000, row + 50, fill="black", font="Arial 11 bold", text=x["exercise"])
canvasmain.create_text(column - 80, row + 75, fill="black", font="Arial 11 bold",
text="Maximum Hours Left Alone Per Day: ")
canvasmain.create_text(500, row + 75, fill="black", font="Arial 11 bold", text=x["hours"])
canvasmain.create_text(1000, row + 75, fill="black", font="Arial 11 bold", text=x["hours"])
canvasmain.create_text(column - 25, row + 100, fill="black", font="Arial 11 bold",
text="Average Lifespan: ")
canvasmain.create_text(500, row + 100, fill="black", font="Arial 11 bold", text=x["life"])
canvasmain.create_text(1000, row + 100, fill="black", font="Arial 11 bold", text=x["life"])
canvasmain.create_text(column - 25, row + 125, fill="black", font="Arial 11 bold", text="Maximum Growth: ")
canvasmain.create_text(500, row + 125, fill="black", font="Arial 11 bold", text=x["growth"])
canvasmain.create_text(1000, row + 125, fill="black", font="Arial 11 bold", text=x["growth"])
row += 150
canvasmain.update_idletasks()
canvasmain.configure(scrollregion=canvasmain.bbox('all'),
yscrollcommand=scrollbar.set)
canvasmain.pack(fill='both', expand=True, side='left')
scrollbar.pack(fill='y', side='right')
else:
canvasmain.create_text(500, 400, fill="black", font="Arial 11 bold",
text="Unable to get dog breeds please try again.")
......@@ -102,26 +109,26 @@ def getDogsForDelete():
deleter = t.request('DELETE', "http://cs2s.yorkdc.net:5002/dogs/" + breed)
if deleter.status == 200:
canvasmain.delete("all")
canvasmain.create_text(500, 400, fill="black", font="Arial 10 bold",
canvasmain.create_text(1000, 400, fill="black", font="Arial 10 bold",
text="Dog Breed has been deleted from our database.")
else:
canvasmain.create_text(500, 400, fill="black", font="Arial 10 bold",
canvasmain.create_text(1000, 400, fill="black", font="Arial 10 bold",
text="Dog breed unable to be deleted please try again")
response = t.request('GET', "http://cs2s.yorkdc.net:5002/dogs")
if response:
canvasmain.delete("all")
canvasmain.create_text(500, 75, fill="black", font="Arial 35 bold", text="Delete Dog Breed from Our Database")
canvasmain.create_text(1000, 75, fill="black", font="Arial 35 bold", text="Delete Dog Breed from Our Database")
dogs = json.loads(response.data)
lb = Listbox(canvasmain, height=10)
place = 0
for i in dogs:
lb.insert(place, i["dogbreed"])
place += 1
canvasmain.create_window(400, 150, anchor=NW, window=lb)
canvasmain.create_window(900, 150, anchor=NW, window=lb)
dBDeleteBtn = Button(window, text="Delete Dog Breed", command=handler)
dBDeleteBtn.pack(pady=20)
canvasmain.create_window(415, 325, anchor=NW, window=dBDeleteBtn)
canvasmain.create_window(915, 325, anchor=NW, window=dBDeleteBtn)
else:
print('Request returned an error.')
......@@ -129,45 +136,45 @@ def getDogsForDelete():
def addDogCanvasUpdate():
def addDog():
if int(entry2.get()) and int(entry3.get()) and int(entry4.get()) and int(entry5.get()):
canvastitle.create_text(500, 230, fill="black", font="Arial 10 bold",
canvastitle.create_text(1000, 230, fill="black", font="Arial 10 bold",
text="correct types")
adddog = t.request('POST', 'http://cs2s.yorkdc.net:5002/senddogs',
fields={'dogbreed': entry1.get(), 'exercise': entry2.get(), 'hours': entry3.get(),
'years': entry4.get(), 'growth': entry5.get(), 'image': entry6.get()})
if adddog.status == 200:
canvasmain.delete("all")
canvasmain.create_text(500, 400, fill="black", font="Arial 10 bold",
canvasmain.create_text(1000, 400, fill="black", font="Arial 10 bold",
text="Dog Breed has been added to our database.")
else:
canvastitle.create_text(500, 230, fill="black", font="Arial 10 bold",
canvastitle.create_text(1000, 230, fill="black", font="Arial 10 bold",
text="Dog Breed was unable to be added to our database. Please try again.")
else:
canvastitle.create_text(500, 230, fill="black", font="Arial 10 bold",
canvastitle.create_text(1000, 230, fill="black", font="Arial 10 bold",
text="Incorrect entry types. Please try again.")
canvasmain.delete("all")
canvasmain.create_text(500, 75, fill="black", font="Arial 40 bold", text="Add a Dog Breed to Our Database")
canvasmain.create_text(400, 170, fill="black", font="Arial 15 bold", text="Dog Breed: ")
canvasmain.create_text(1000, 75, fill="black", font="Arial 40 bold", text="Add a Dog Breed to Our Database")
canvasmain.create_text(900, 170, fill="black", font="Arial 15 bold", text="Dog Breed: ")
entry1 = Entry(window)
canvasmain.create_window(550, 170, window=entry1)
canvasmain.create_text(290, 210, fill="black", font="Arial 15 bold", text="Minimum Exercise Per Day (Hours): ")
canvasmain.create_window(1050, 170, window=entry1)
canvasmain.create_text(790, 210, fill="black", font="Arial 15 bold", text="Minimum Exercise Per Day (Hours): ")
entry2 = Entry(window)
canvasmain.create_window(550, 210, window=entry2)
canvasmain.create_text(290, 250, fill="black", font="Arial 15 bold", text="Maximum Hours Left Alone Per Day: ")
canvasmain.create_window(1050, 210, window=entry2)
canvasmain.create_text(790, 250, fill="black", font="Arial 15 bold", text="Maximum Hours Left Alone Per Day: ")
entry3 = Entry(window)
canvasmain.create_window(550, 250, window=entry3)
canvasmain.create_text(340, 290, fill="black", font="Arial 15 bold", text="Average Lifespan (Years): ")
canvasmain.create_window(1050, 250, window=entry3)
canvasmain.create_text(840, 290, fill="black", font="Arial 15 bold", text="Average Lifespan (Years): ")
entry4 = Entry(window)
canvasmain.create_window(550, 290, window=entry4)
canvasmain.create_text(340, 330, fill="black", font="Arial 15 bold", text="Maximum Growth (cm): ")
canvasmain.create_window(1050, 290, window=entry4)
canvasmain.create_text(840, 330, fill="black", font="Arial 15 bold", text="Maximum Growth (cm): ")
entry5 = Entry(window)
canvasmain.create_window(550, 330, window=entry5)
canvasmain.create_text(340, 370, fill="black", font="Arial 15 bold", text="Dog Image (url address): ")
canvasmain.create_window(1050, 330, window=entry5)
canvasmain.create_text(840, 370, fill="black", font="Arial 15 bold", text="Dog Image (url address): ")
entry6 = Entry(window)
canvasmain.create_window(550, 370, window=entry6)
canvasmain.create_window(1050, 370, window=entry6)
submitBtn = Button(window, text="Submit", command=addDog)
submitBtn.pack(pady=20)
canvasmain.create_window(f'{(width / 4)}', f'{((height / 3) * 1.15)}', anchor=NW, window=submitBtn)
canvasmain.create_window(900, 400, anchor=NW, window=submitBtn)
def menuCanvasUpdate():
......@@ -183,14 +190,14 @@ def updateDogCanvasUpdate():
fields={'dogbreednospace': breed, 'dogimage': updateurl.get()})
if updater.status == 200:
canvasmain.delete("all")
canvasmain.create_text(500, 400, fill="black", font="Arial 10 bold",
canvasmain.create_text(1000, 400, fill="black", font="Arial 10 bold",
text="Dog Breed image has been updated.")
else:
canvasmain.create_text(500, 400, fill="black", font="Arial 10 bold",
canvasmain.create_text(1000, 400, fill="black", font="Arial 10 bold",
text="Dog Breed image unable to update. Please try again.")
canvasmain.delete("all")
canvasmain.create_text(500, 75, fill="black", font="Arial 40 bold", text="Update Dog Breed From Database")
canvasmain.create_text(1000, 75, fill="black", font="Arial 40 bold", text="Update Dog Breed From Database")
response = t.request('GET', "http://cs2s.yorkdc.net:5002/dogs")
if response:
dogs = json.loads(response.data)
......@@ -199,13 +206,13 @@ def updateDogCanvasUpdate():
for i in dogs:
lb.insert(place, i["dogbreed"])
place += 1
canvasmain.create_window(400, 150, anchor=NW, window=lb)
canvasmain.create_text(400, 350, fill="black", font="Arial 15 bold", text="Dog Image (url): ")
canvasmain.create_window(900, 150, anchor=NW, window=lb)
canvasmain.create_text(900, 350, fill="black", font="Arial 15 bold", text="Dog Image (url): ")
updateurl = Entry(window)
canvasmain.create_window(550, 350, window=updateurl)
canvasmain.create_window(1050, 350, window=updateurl)
dBUpdateBtn = Button(window, text="Update Dog Image", command=handler)
dBUpdateBtn.pack()
canvasmain.create_window(625, 345, anchor=NW, window=dBUpdateBtn)
canvasmain.create_window(1125, 345, anchor=NW, window=dBUpdateBtn)
window.title("Dog Breed For You")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment