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

Update main.py

parent 5a6beac8
import base64
from tkinter import * from tkinter import *
from tkinter.ttk import * from tkinter.ttk import *
from urllib.request import urlopen
import urllib3 import urllib3
import json import json
...@@ -10,6 +8,7 @@ window = Tk() ...@@ -10,6 +8,7 @@ window = Tk()
width = window.winfo_screenwidth() width = window.winfo_screenwidth()
height = window.winfo_screenheight() height = window.winfo_screenheight()
canvasmain = Canvas(window, width=f'{width / 2}', height=f'{height * 4}', bg='#cae8dc') canvasmain = Canvas(window, width=f'{width / 2}', height=f'{height * 4}', bg='#cae8dc')
scrollbar = Scrollbar(window, orient="vertical", command=canvasmain.yview)
def login(): def login():
...@@ -42,54 +41,62 @@ def logout(): ...@@ -42,54 +41,62 @@ def logout():
canvastitle.create_window(550, 170, window=password) canvastitle.create_window(550, 170, window=password)
loginBtn = Button(window, text="Login", command=login) loginBtn = Button(window, text="Login", command=login)
loginBtn.pack(pady=10) 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(): 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 # Dog Breed Info Button
dogBreedInfoBtn = Button(window, text="Get Dog Breed Information", width=30, command=getDogs) dogBreedInfoBtn = Button(window, text="Get Dog Breed Information", width=30, command=getDogs)
dogBreedInfoBtn.pack(pady=20) 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 # Add Dog Breed Button
dogBreedAddBtn = Button(window, text="Add Dog Breed", width=30, command=addDogCanvasUpdate) dogBreedAddBtn = Button(window, text="Add Dog Breed", width=30, command=addDogCanvasUpdate)
dogBreedAddBtn.pack(pady=20) 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 # Delete Dog Breed Button
dogBreedDeleteBtn = Button(window, text="Delete Dog Breed", width=30, command=getDogsForDelete) dogBreedDeleteBtn = Button(window, text="Delete Dog Breed", width=30, command=getDogsForDelete)
dogBreedDeleteBtn.pack(pady=20) 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 # Update Dog Breed Button
dogBreedUpdateBtn = Button(window, text="Update Dog Image", width=30, command=updateDogCanvasUpdate) dogBreedUpdateBtn = Button(window, text="Update Dog Image", width=30, command=updateDogCanvasUpdate)
dogBreedUpdateBtn.pack(pady=20) dogBreedUpdateBtn.pack(pady=20)
canvasmain.create_window(400, 300, anchor=NW, window=dogBreedUpdateBtn) canvasmain.create_window(900, 300, anchor=NW, window=dogBreedUpdateBtn)
canvasmain.pack(pady=20) canvasmain.pack(fill='both', pady=20)
def getDogs(): def getDogs():
t = urllib3.PoolManager() t = urllib3.PoolManager()
response = t.request('GET', "http://cs2s.yorkdc.net:5002/dogs") response = t.request('GET', "http://cs2s.yorkdc.net:5002/dogs")
if response.status == 200: if response.status == 200:
scrollbar.destroy()
canvasmain.delete("all") 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) dogs = json.loads(response.data)
column = 350 column = 900
row = 125 row = 125
for x in dogs: for x in dogs:
canvasmain.create_text(column, row + 25, fill="black", font="Arial 11 bold", text="Dog Breed: ") 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 + 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", canvasmain.create_text(column - 50, row + 50, fill="black", font="Arial 11 bold",
text="Minimum Exercise Per Day: ") 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", canvasmain.create_text(column - 80, row + 75, fill="black", font="Arial 11 bold",
text="Maximum Hours Left Alone Per Day: ") 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", canvasmain.create_text(column - 25, row + 100, fill="black", font="Arial 11 bold",
text="Average Lifespan: ") 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(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 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: else:
canvasmain.create_text(500, 400, fill="black", font="Arial 11 bold", canvasmain.create_text(500, 400, fill="black", font="Arial 11 bold",
text="Unable to get dog breeds please try again.") text="Unable to get dog breeds please try again.")
...@@ -102,26 +109,26 @@ def getDogsForDelete(): ...@@ -102,26 +109,26 @@ def getDogsForDelete():
deleter = t.request('DELETE', "http://cs2s.yorkdc.net:5002/dogs/" + breed) deleter = t.request('DELETE', "http://cs2s.yorkdc.net:5002/dogs/" + breed)
if deleter.status == 200: if deleter.status == 200:
canvasmain.delete("all") 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.") text="Dog Breed has been deleted from our database.")
else: 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") text="Dog breed unable to be deleted please try again")
response = t.request('GET', "http://cs2s.yorkdc.net:5002/dogs") response = t.request('GET', "http://cs2s.yorkdc.net:5002/dogs")
if response: if response:
canvasmain.delete("all") 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) dogs = json.loads(response.data)
lb = Listbox(canvasmain, height=10) lb = Listbox(canvasmain, height=10)
place = 0 place = 0
for i in dogs: for i in dogs:
lb.insert(place, i["dogbreed"]) lb.insert(place, i["dogbreed"])
place += 1 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 = Button(window, text="Delete Dog Breed", command=handler)
dBDeleteBtn.pack(pady=20) dBDeleteBtn.pack(pady=20)
canvasmain.create_window(415, 325, anchor=NW, window=dBDeleteBtn) canvasmain.create_window(915, 325, anchor=NW, window=dBDeleteBtn)
else: else:
print('Request returned an error.') print('Request returned an error.')
...@@ -129,45 +136,45 @@ def getDogsForDelete(): ...@@ -129,45 +136,45 @@ def getDogsForDelete():
def addDogCanvasUpdate(): def addDogCanvasUpdate():
def addDog(): def addDog():
if int(entry2.get()) and int(entry3.get()) and int(entry4.get()) and int(entry5.get()): 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") text="correct types")
adddog = t.request('POST', 'http://cs2s.yorkdc.net:5002/senddogs', adddog = t.request('POST', 'http://cs2s.yorkdc.net:5002/senddogs',
fields={'dogbreed': entry1.get(), 'exercise': entry2.get(), 'hours': entry3.get(), fields={'dogbreed': entry1.get(), 'exercise': entry2.get(), 'hours': entry3.get(),
'years': entry4.get(), 'growth': entry5.get(), 'image': entry6.get()}) 'years': entry4.get(), 'growth': entry5.get(), 'image': entry6.get()})
if adddog.status == 200: if adddog.status == 200:
canvasmain.delete("all") 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.") text="Dog Breed has been added to our database.")
else: 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.") text="Dog Breed was unable to be added to our database. Please try again.")
else: 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.") text="Incorrect entry types. Please try again.")
canvasmain.delete("all") 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(1000, 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(900, 170, fill="black", font="Arial 15 bold", text="Dog Breed: ")
entry1 = Entry(window) entry1 = Entry(window)
canvasmain.create_window(550, 170, window=entry1) canvasmain.create_window(1050, 170, window=entry1)
canvasmain.create_text(290, 210, fill="black", font="Arial 15 bold", text="Minimum Exercise Per Day (Hours): ") canvasmain.create_text(790, 210, fill="black", font="Arial 15 bold", text="Minimum Exercise Per Day (Hours): ")
entry2 = Entry(window) entry2 = Entry(window)
canvasmain.create_window(550, 210, window=entry2) canvasmain.create_window(1050, 210, window=entry2)
canvasmain.create_text(290, 250, fill="black", font="Arial 15 bold", text="Maximum Hours Left Alone Per Day: ") canvasmain.create_text(790, 250, fill="black", font="Arial 15 bold", text="Maximum Hours Left Alone Per Day: ")
entry3 = Entry(window) entry3 = Entry(window)
canvasmain.create_window(550, 250, window=entry3) canvasmain.create_window(1050, 250, window=entry3)
canvasmain.create_text(340, 290, fill="black", font="Arial 15 bold", text="Average Lifespan (Years): ") canvasmain.create_text(840, 290, fill="black", font="Arial 15 bold", text="Average Lifespan (Years): ")
entry4 = Entry(window) entry4 = Entry(window)
canvasmain.create_window(550, 290, window=entry4) canvasmain.create_window(1050, 290, window=entry4)
canvasmain.create_text(340, 330, fill="black", font="Arial 15 bold", text="Maximum Growth (cm): ") canvasmain.create_text(840, 330, fill="black", font="Arial 15 bold", text="Maximum Growth (cm): ")
entry5 = Entry(window) entry5 = Entry(window)
canvasmain.create_window(550, 330, window=entry5) canvasmain.create_window(1050, 330, window=entry5)
canvasmain.create_text(340, 370, fill="black", font="Arial 15 bold", text="Dog Image (url address): ") canvasmain.create_text(840, 370, fill="black", font="Arial 15 bold", text="Dog Image (url address): ")
entry6 = Entry(window) 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 = Button(window, text="Submit", command=addDog)
submitBtn.pack(pady=20) 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(): def menuCanvasUpdate():
...@@ -183,14 +190,14 @@ def updateDogCanvasUpdate(): ...@@ -183,14 +190,14 @@ def updateDogCanvasUpdate():
fields={'dogbreednospace': breed, 'dogimage': updateurl.get()}) fields={'dogbreednospace': breed, 'dogimage': updateurl.get()})
if updater.status == 200: if updater.status == 200:
canvasmain.delete("all") 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.") text="Dog Breed image has been updated.")
else: 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.") text="Dog Breed image unable to update. Please try again.")
canvasmain.delete("all") 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") response = t.request('GET', "http://cs2s.yorkdc.net:5002/dogs")
if response: if response:
dogs = json.loads(response.data) dogs = json.loads(response.data)
...@@ -199,13 +206,13 @@ def updateDogCanvasUpdate(): ...@@ -199,13 +206,13 @@ def updateDogCanvasUpdate():
for i in dogs: for i in dogs:
lb.insert(place, i["dogbreed"]) lb.insert(place, i["dogbreed"])
place += 1 place += 1
canvasmain.create_window(400, 150, anchor=NW, window=lb) canvasmain.create_window(900, 150, anchor=NW, window=lb)
canvasmain.create_text(400, 350, fill="black", font="Arial 15 bold", text="Dog Image (url): ") canvasmain.create_text(900, 350, fill="black", font="Arial 15 bold", text="Dog Image (url): ")
updateurl = Entry(window) 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 = Button(window, text="Update Dog Image", command=handler)
dBUpdateBtn.pack() 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") window.title("Dog Breed For You")
...@@ -224,4 +231,4 @@ loginBtn = Button(window, text="Login", command=login) ...@@ -224,4 +231,4 @@ loginBtn = Button(window, text="Login", command=login)
loginBtn.pack(pady=10) loginBtn.pack(pady=10)
loginBtn_window = canvastitle.create_window(450, 190, anchor=NW, window=loginBtn) loginBtn_window = canvastitle.create_window(450, 190, anchor=NW, window=loginBtn)
canvastitle.pack(pady=20) canvastitle.pack(pady=20)
window.mainloop() window.mainloop()
\ No newline at end of file
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