-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrettyHTML.pyw
More file actions
49 lines (35 loc) · 1.07 KB
/
PrettyHTML.pyw
File metadata and controls
49 lines (35 loc) · 1.07 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
#info
name = 'PrettyHTML'
version = '1.0.0'
author= 'Filip Rokita'
website = 'www.filiprokita.com'
#import
import tkinter as tk
from bs4 import BeautifulSoup
from tkinter import filedialog
from tkinter import messagebox
#def
def choose():
global filedir; filedir = filedialog.askopenfilename(title=name, initialdir='./', filetypes=[('html', '*.html')])
try:
f = open(filedir, 'r')
prettyB['state'] = tk.NORMAL
global data; data = f.read()
f.close()
except:
messagebox.showerror(title=name, message='Choose file!')
def pretty():
soup = BeautifulSoup(data, 'html.parser')
prettyfied = soup.prettify()
f = open(filedir, 'w')
f.write(prettyfied)
f.close()
#main
root = tk.Tk()
root.title(name)
root.geometry('300x100')
root.resizable(False, False)
chooseB = tk.Button(root, text='Choose File', command=choose, width=15); chooseB.pack()
prettyB = tk.Button(root, text='Prettify', state=tk.DISABLED, command=pretty, width=15); prettyB.pack(pady=10)
authorL = tk.Label(root, text=website); authorL.pack()
root.mainloop()