-
Notifications
You must be signed in to change notification settings - Fork 0
/
icontobase64.py
48 lines (40 loc) · 1.39 KB
/
icontobase64.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
# -*- coding:utf -8 -*-
__version__ = '1.0'
import base64
from tkinter import *
from tkinter import filedialog as fd
root = Tk()
root.title("Icon to base64 " +str(__version__))
root.resizable(width=False, height=False)
root.geometry("380x250+300+300")
calculated_text = Text(root,height=15, width=50)
myFormats = [
('TXT files','*.txt'),
('HTML files','*.html;.htm'),
('All files','*.*'),
]
def insertImg():
file_name = fd.askopenfilename()
f = open(file_name, 'rb')
s = f.read()
calculated_text.insert('1.0',(str(base64.b64encode(s))[2:])[:-1])
f.close()
def extractText():
file_name = fd.asksaveasfilename(parent=root,filetypes=myFormats,defaultextension='')
f = open(file_name, 'w')
s = calculated_text.get(1.0, END)
f.write(s)
f.close()
def erase():
calculated_text.delete('1.0', END)
b1 = Button(text="Open",command=insertImg)
b1.grid(row=3, column=0, sticky=E, padx=5, pady=8,)
b2 = Button(text="Save", command=extractText)
b2.grid(row=3, column=1, sticky=E, padx=5, pady=8,)
erase_button = Button(text="Clear", command=erase)
erase_button.grid(row=3, column=2, padx=35, pady=8, sticky="W")
scrollb = Scrollbar(root, command=calculated_text.yview)
scrollb.grid(row=4, column=4, sticky='nsew')
calculated_text.grid(row=4, column=0, sticky='nsew', columnspan=3)
calculated_text.configure(yscrollcommand=scrollb.set)
root.mainloop()