Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pythonclient
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
charley.punshon
pythonclient
Commits
73abbefa
Commit
73abbefa
authored
Apr 11, 2021
by
charley.punshon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update main.py
parent
5a6beac8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
46 deletions
+53
-46
main.py
main.py
+53
-46
No files found.
main.py
View file @
73abbefa
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
(
4
00
,
150
,
anchor
=
NW
,
window
=
dogBreedInfoBtn
)
canvasmain
.
create_window
(
9
00
,
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
(
4
00
,
200
,
anchor
=
NW
,
window
=
dogBreedAddBtn
)
canvasmain
.
create_window
(
9
00
,
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
(
4
00
,
250
,
anchor
=
NW
,
window
=
dogBreedDeleteBtn
)
canvasmain
.
create_window
(
9
00
,
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
(
4
00
,
300
,
anchor
=
NW
,
window
=
dogBreedUpdateBtn
)
canvasmain
.
pack
(
pady
=
20
)
canvasmain
.
create_window
(
9
00
,
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
=
35
0
column
=
90
0
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
(
5
00
,
row
+
50
,
fill
=
"black"
,
font
=
"Arial 11 bold"
,
text
=
x
[
"exercise"
])
canvasmain
.
create_text
(
10
00
,
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
(
5
00
,
row
+
75
,
fill
=
"black"
,
font
=
"Arial 11 bold"
,
text
=
x
[
"hours"
])
canvasmain
.
create_text
(
10
00
,
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
(
5
00
,
row
+
100
,
fill
=
"black"
,
font
=
"Arial 11 bold"
,
text
=
x
[
"life"
])
canvasmain
.
create_text
(
10
00
,
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
(
5
00
,
row
+
125
,
fill
=
"black"
,
font
=
"Arial 11 bold"
,
text
=
x
[
"growth"
])
canvasmain
.
create_text
(
10
00
,
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
(
5
00
,
400
,
fill
=
"black"
,
font
=
"Arial 10 bold"
,
canvasmain
.
create_text
(
10
00
,
400
,
fill
=
"black"
,
font
=
"Arial 10 bold"
,
text
=
"Dog Breed has been deleted from our database."
)
else
:
canvasmain
.
create_text
(
5
00
,
400
,
fill
=
"black"
,
font
=
"Arial 10 bold"
,
canvasmain
.
create_text
(
10
00
,
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
(
5
00
,
75
,
fill
=
"black"
,
font
=
"Arial 35 bold"
,
text
=
"Delete Dog Breed from Our Database"
)
canvasmain
.
create_text
(
10
00
,
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
(
4
00
,
150
,
anchor
=
NW
,
window
=
lb
)
canvasmain
.
create_window
(
9
00
,
150
,
anchor
=
NW
,
window
=
lb
)
dBDeleteBtn
=
Button
(
window
,
text
=
"Delete Dog Breed"
,
command
=
handler
)
dBDeleteBtn
.
pack
(
pady
=
20
)
canvasmain
.
create_window
(
4
15
,
325
,
anchor
=
NW
,
window
=
dBDeleteBtn
)
canvasmain
.
create_window
(
9
15
,
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
(
5
00
,
230
,
fill
=
"black"
,
font
=
"Arial 10 bold"
,
canvastitle
.
create_text
(
10
00
,
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
(
5
00
,
400
,
fill
=
"black"
,
font
=
"Arial 10 bold"
,
canvasmain
.
create_text
(
10
00
,
400
,
fill
=
"black"
,
font
=
"Arial 10 bold"
,
text
=
"Dog Breed has been added to our database."
)
else
:
canvastitle
.
create_text
(
5
00
,
230
,
fill
=
"black"
,
font
=
"Arial 10 bold"
,
canvastitle
.
create_text
(
10
00
,
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
(
5
00
,
230
,
fill
=
"black"
,
font
=
"Arial 10 bold"
,
canvastitle
.
create_text
(
10
00
,
230
,
fill
=
"black"
,
font
=
"Arial 10 bold"
,
text
=
"Incorrect entry types. Please try again."
)
canvasmain
.
delete
(
"all"
)
canvasmain
.
create_text
(
5
00
,
75
,
fill
=
"black"
,
font
=
"Arial 40 bold"
,
text
=
"Add a Dog Breed to Our Database"
)
canvasmain
.
create_text
(
4
00
,
170
,
fill
=
"black"
,
font
=
"Arial 15 bold"
,
text
=
"Dog Breed: "
)
canvasmain
.
create_text
(
10
00
,
75
,
fill
=
"black"
,
font
=
"Arial 40 bold"
,
text
=
"Add a Dog Breed to Our Database"
)
canvasmain
.
create_text
(
9
00
,
170
,
fill
=
"black"
,
font
=
"Arial 15 bold"
,
text
=
"Dog Breed: "
)
entry1
=
Entry
(
window
)
canvasmain
.
create_window
(
5
50
,
170
,
window
=
entry1
)
canvasmain
.
create_text
(
2
90
,
210
,
fill
=
"black"
,
font
=
"Arial 15 bold"
,
text
=
"Minimum Exercise Per Day (Hours): "
)
canvasmain
.
create_window
(
10
50
,
170
,
window
=
entry1
)
canvasmain
.
create_text
(
7
90
,
210
,
fill
=
"black"
,
font
=
"Arial 15 bold"
,
text
=
"Minimum Exercise Per Day (Hours): "
)
entry2
=
Entry
(
window
)
canvasmain
.
create_window
(
5
50
,
210
,
window
=
entry2
)
canvasmain
.
create_text
(
2
90
,
250
,
fill
=
"black"
,
font
=
"Arial 15 bold"
,
text
=
"Maximum Hours Left Alone Per Day: "
)
canvasmain
.
create_window
(
10
50
,
210
,
window
=
entry2
)
canvasmain
.
create_text
(
7
90
,
250
,
fill
=
"black"
,
font
=
"Arial 15 bold"
,
text
=
"Maximum Hours Left Alone Per Day: "
)
entry3
=
Entry
(
window
)
canvasmain
.
create_window
(
5
50
,
250
,
window
=
entry3
)
canvasmain
.
create_text
(
3
40
,
290
,
fill
=
"black"
,
font
=
"Arial 15 bold"
,
text
=
"Average Lifespan (Years): "
)
canvasmain
.
create_window
(
10
50
,
250
,
window
=
entry3
)
canvasmain
.
create_text
(
8
40
,
290
,
fill
=
"black"
,
font
=
"Arial 15 bold"
,
text
=
"Average Lifespan (Years): "
)
entry4
=
Entry
(
window
)
canvasmain
.
create_window
(
5
50
,
290
,
window
=
entry4
)
canvasmain
.
create_text
(
3
40
,
330
,
fill
=
"black"
,
font
=
"Arial 15 bold"
,
text
=
"Maximum Growth (cm): "
)
canvasmain
.
create_window
(
10
50
,
290
,
window
=
entry4
)
canvasmain
.
create_text
(
8
40
,
330
,
fill
=
"black"
,
font
=
"Arial 15 bold"
,
text
=
"Maximum Growth (cm): "
)
entry5
=
Entry
(
window
)
canvasmain
.
create_window
(
5
50
,
330
,
window
=
entry5
)
canvasmain
.
create_text
(
3
40
,
370
,
fill
=
"black"
,
font
=
"Arial 15 bold"
,
text
=
"Dog Image (url address): "
)
canvasmain
.
create_window
(
10
50
,
330
,
window
=
entry5
)
canvasmain
.
create_text
(
8
40
,
370
,
fill
=
"black"
,
font
=
"Arial 15 bold"
,
text
=
"Dog Image (url address): "
)
entry6
=
Entry
(
window
)
canvasmain
.
create_window
(
5
50
,
370
,
window
=
entry6
)
canvasmain
.
create_window
(
10
50
,
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
(
5
00
,
400
,
fill
=
"black"
,
font
=
"Arial 10 bold"
,
canvasmain
.
create_text
(
10
00
,
400
,
fill
=
"black"
,
font
=
"Arial 10 bold"
,
text
=
"Dog Breed image has been updated."
)
else
:
canvasmain
.
create_text
(
5
00
,
400
,
fill
=
"black"
,
font
=
"Arial 10 bold"
,
canvasmain
.
create_text
(
10
00
,
400
,
fill
=
"black"
,
font
=
"Arial 10 bold"
,
text
=
"Dog Breed image unable to update. Please try again."
)
canvasmain
.
delete
(
"all"
)
canvasmain
.
create_text
(
5
00
,
75
,
fill
=
"black"
,
font
=
"Arial 40 bold"
,
text
=
"Update Dog Breed From Database"
)
canvasmain
.
create_text
(
10
00
,
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
(
4
00
,
150
,
anchor
=
NW
,
window
=
lb
)
canvasmain
.
create_text
(
4
00
,
350
,
fill
=
"black"
,
font
=
"Arial 15 bold"
,
text
=
"Dog Image (url): "
)
canvasmain
.
create_window
(
9
00
,
150
,
anchor
=
NW
,
window
=
lb
)
canvasmain
.
create_text
(
9
00
,
350
,
fill
=
"black"
,
font
=
"Arial 15 bold"
,
text
=
"Dog Image (url): "
)
updateurl
=
Entry
(
window
)
canvasmain
.
create_window
(
5
50
,
350
,
window
=
updateurl
)
canvasmain
.
create_window
(
10
50
,
350
,
window
=
updateurl
)
dBUpdateBtn
=
Button
(
window
,
text
=
"Update Dog Image"
,
command
=
handler
)
dBUpdateBtn
.
pack
()
canvasmain
.
create_window
(
6
25
,
345
,
anchor
=
NW
,
window
=
dBUpdateBtn
)
canvasmain
.
create_window
(
11
25
,
345
,
anchor
=
NW
,
window
=
dBUpdateBtn
)
window
.
title
(
"Dog Breed For You"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment