-
Notifications
You must be signed in to change notification settings - Fork 1
/
gui.py
126 lines (116 loc) · 4.03 KB
/
gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
'''
NAME: Mavey Ma
LAST EDITED: March 30, 2016
DESCRIPTION: Graphical User Interface for iDigit with three buttons:
[DRAWPAD] - User draws number with mouse
[UPLOAD] - Browse and upload photo to analyze
[EXIT] - Closes window
'''
from Tkinter import *
import Tkinter as tk
import tkFont
from tkFileDialog import askopenfilename
from PIL import Image, ImageTk
#==========FUNCTION DEFINITIONS==========
#BUTTON DRAWPAD: ALLOWS USER TO OPEN DRAWPAD
def paint(event):
black = "#000000"
x1, y1 = (event.x - 5), (event.y - 5)
x2, y2 = (event.x + 5), (event.y + 5)
w.create_oval(x1, y1, x2, y2, fill=black)
def clear():
w.delete("all")
def dibujar():
canvas_width = 350
canvas_height = 350
#c = Tk()
#INSTRUCTIONS IN UPPER RIGHT HAND CORNER
message = Label(master, text = "Press & slowly drag the mouse to draw.",
font=courierText)
message.place(x=0,y=25)
#WHITE CANVAS
d = Canvas(master, width=canvas_width, height=canvas_height)
#d.place(x=175, y=100)
d.bind("<B1-Motion>", paint)
#CLEAR CANVAS
clean = Button(master, text="CLEAR CANVAS", font=courierFont,
fg="black", bg="white",
activeforeground="white", activebackground="black",
command=clear, width = 12)
clean.place(x=460, y=0)
#BUTTON UPLOAD: ALLOWS USER TO SELECT A FILE TO UPLOAD
def browse():
#Tk().withdraw() #this would prevent the root window from appearing
filename = askopenfilename() #show an "Open" dialog box and return the path to the selected file
im = Image.open(filename)
tkimage = ImageTk.PhotoImage(im)
tk.Label(master, image=tkimage).pack()
return filename
#==========STYLE SET UP==========
#BOX
master = Tk()
#CREATE A CANVAS w SIZE 800x500
w = Canvas(master, width=600, height=500)
#CONTROL WHERE THINGS ARE LOCATED: EXPAND, FILL, SIDES
w.pack()
#SET FONT
courierFont = tkFont.Font(family="Courier", size=21, weight=tkFont.BOLD)
courierText = tkFont.Font(family="Courier", size=15, weight=tkFont.BOLD)
#WINDOW TITLE
master.title("i d i g i t [Number Identifier]")
#WELCOME TEXT
welcome = Label(master, text = "Welcome to iDigit.",
font=courierText)
welcome.place(x=0,y=0)
#NOTE: TOP FRAME IS DEFAULT
#BOTTOM LOCATION
bottomFrame = Frame(master)
bottomFrame.pack(side=BOTTOM)
#RIGHT LOCATION
rightFrame = Frame(master)
rightFrame.pack(side=RIGHT)
#LEFT LOCATION
leftFrame = Frame(master)
leftFrame.pack(side=LEFT)
#==========BUTTONS==========
""" TEMPLATE FOR BUTTON PARAMETERS
BUTTON(LOCATION, TEXT, FONT,
FOREGROUND(COLOR OF TEXT), BACKGROUND,
HOVERTEXT, HOVERGROUND)
"""
#BUTTON DRAWPAD: ALLOWS USER TO OPEN DRAWPAD
drawPadButton = Button(leftFrame, text="DRAWPAD", font=courierFont,
fg="black", bg="LightBlue",
activeforeground="white", activebackground="#00BFFF",
command=dibujar, width = 12)
drawPadButton.pack(side=LEFT)
#BUTTON UPLOAD: ALLOWS USER TO SELECT A FILE TO UPLOAD
uploadButton = Button(leftFrame, text="UPLOAD", font=courierFont,
fg="black", bg="LightGreen",
activeforeground="white", activebackground="#00BA37",
command=browse, width = 12)
uploadButton.pack(side=LEFT)
#BUTTON EXIT: CLOSES WINDOW
resetButton = Button(leftFrame, text="EXIT", font=courierFont,
fg="black", bg="pink",
activeforeground="white", activebackground="#FF0DF2",
command=quit, width = 12)
resetButton.pack(side=LEFT)
#==========PROCESS INPUT HERE==========
#END PROGRAM, RUN IT
mainloop()
"""
import Tkinter as tk
#Creates a window with a quit button that does so when clicked.
class Application(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.grid()
self.createWidgets()
def createWidgets(self):
self.quitButton = tk.Button(self, text='Quit', command=self.quit)
self.quitButton.grid()
app = Application()
app.master.title('Sample application')
app.mainloop()
"""