forked from McJazzy/hexagonpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
57 lines (43 loc) · 1.75 KB
/
gui.py
File metadata and controls
57 lines (43 loc) · 1.75 KB
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
from tkinter import *
from tkinter import filedialog
from image import hexagonify
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self,master)
self.pack()
self.createWidgets()
"""Opens a file chooser dialog to select a picture"""
def browsefunc(self):
filename = filedialog.askopenfilename()
self.PATHLABEL.config(text=filename)
"""Hexagonifies the image and shows it to the user"""
def generateImage(self):
if str.isdigit(self.HEX_SIZE.get()) and self.PATHLABEL.cget("text") is not "":
hex_size = int(self.HEX_SIZE.get())
file = self.PATHLABEL.cget("text")
self.im = hexagonify(file, hex_size)
self.im.show()
"""Opens a file saver dialog and saves image"""
def saveIm(self):
files = [("PNG","*.png"),("JPEG", "*.jpg"),("All Files", "*.*")]
filename = filedialog.asksaveasfilename(filetypes = files, defaultextension = files)
if filename:
self.im.save(filename, quality = 100, subsampling=0)
"""Sets up the GUI"""
def createWidgets(self):
self.BROWSEBUTTON = Button(self, text="Browse", command=self.browsefunc)
self.BROWSEBUTTON.grid(row=0, column=1)
self.PATHLABEL = Label(self)
self.PATHLABEL.grid(row=0,column=0)
self.HEX_SIZE = Entry(self,textvariable=StringVar(self,value="20"))
self.HEX_SIZE.grid(row=1,column=1)
self.HEX_LABEL = Label(self,text="Hexagon size")
self.HEX_LABEL.grid(row=1,column=0)
self.GENERATEBUTTON = Button(self, text="Generate Image", command = self.generateImage)
self.GENERATEBUTTON.grid(row=2,column=0)
self.SAVEBUTTON = Button(self, text="Save", command=self.saveIm)
self.SAVEBUTTON.grid(row=2,column=1)
root = Tk()
app = Application(master=root)
app.mainloop()
root.destroy()