-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyc_compiler.py
More file actions
43 lines (37 loc) · 1.48 KB
/
pyc_compiler.py
File metadata and controls
43 lines (37 loc) · 1.48 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
import py_compile
import tkinter
import tkinter.filedialog
import tkinter.messagebox
def get_file() -> None:
# noinspection PyGlobalUndefined
global path, finish
path = tkinter.filedialog.askopenfilename(filetypes=[("Python file", "*.py")])
if path != '':
finish.config(state=tkinter.NORMAL)
print(path)
def compile_file() -> None:
# noinspection PyGlobalUndefined
global path, finish
try:
py_compile.compile(f'{path}')
print("Check __pycache__ folder")
tkinter.messagebox.showinfo('Successful', message='Check __pycache__ folder')
except py_compile.PyCompileError as err:
print("Error: ", err)
tkinter.messagebox.showerror('Error', message=err)
except FileNotFoundError as err:
print("Error: ", err)
tkinter.messagebox.showerror('Error', message=err)
except Exception as err:
print("Error: ", err)
tkinter.messagebox.showerror('Error', message=err)
finish.config(state=tkinter.DISABLED)
root = tkinter.Tk()
root.title('.pyc Compiler')
frame = tkinter.Frame(root)
path_input = tkinter.Button(frame, text="Choose .py File", command=get_file, width=20)
path_input.grid(row=0, column=0, sticky=tkinter.N + tkinter.S + tkinter.E + tkinter.W)
finish = tkinter.Button(frame, text="Compile", command=compile_file, state=tkinter.DISABLED, width=20)
finish.grid(row=0, column=1, sticky=tkinter.N + tkinter.S + tkinter.E + tkinter.W)
frame.pack(fill="both", expand=True)
root.mainloop()