-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeaMug.py
92 lines (56 loc) · 2.12 KB
/
TeaMug.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
import tkinter
import os
import webbrowser
import easygui
tk = tkinter.Tk()
tk.title('welcome to TeaMug')
def save_as(root,html_code):
file_name = easygui.filesavebox()
root.title(file_name)
file = open(file_name,'w')
file.write(html_code.get('1.0','end-1c'))
file.close()
def save(root,html_code):
file_name = root.title()
if file_name == 'untitled':
save_as(root,html_code)
else:
file = open(file_name,'w')
file.write(html_code.get('1.0','end-1c'))
file.close()
def run_file(root):
file_name = root.title()
current_directory = os.getcwd()
webbrowser.open('file:///' + file_name)
def new_file():
r = tkinter.Tk()
r.title('untitled')
html_code = tkinter.Text(r)
save_file_button = tkinter.Button(r,text = 'Save',command = lambda: save(r,html_code))
save_as_file_button = tkinter.Button(r,text = 'Save As',command = lambda: save_as(r,html_code))
run_file_button = tkinter.Button(r,text = 'Run',command = lambda: run_file(r))
html_code.grid(row = 1)
save_file_button.grid(row = 2)
save_as_file_button.grid(row = 3)
run_file_button.grid(row = 4)
r.mainloop()
def open_existing_file():
file_name = easygui.fileopenbox()
r = tkinter.Tk()
r.title(file_name)
file_text = open(r.title(),'r').read()
html_code = tkinter.Text(r)
html_code.insert(tkinter.END,file_text)
save_file_button = tkinter.Button(r,text = 'Save',command = lambda: save(r,html_code))
save_as_file_button = tkinter.Button(r,text = 'Save As',command = lambda: save_as(r,html_code))
run_file_button = tkinter.Button(r,text = 'Run',command = lambda: run_file(r))
html_code.grid(row = 1)
save_file_button.grid(row = 2)
save_as_file_button.grid(row = 3)
run_file_button.grid(row = 4)
r.mainloop()
open_file_button = tkinter.Button(tk,text = 'open existing file',command = open_existing_file)
new_file_button = tkinter.Button(tk,text = 'create new file',command = new_file)
open_file_button.pack(side = 'left')
new_file_button.pack(side = 'left')
tk.mainloop()