Skip to content

Commit 3bd8c7c

Browse files
authored
Update EzPython.py
1 parent c8cc9a3 commit 3bd8c7c

File tree

1 file changed

+70
-17
lines changed

1 file changed

+70
-17
lines changed

EzPython.py

Lines changed: 70 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from cProfile import label
21
from tkinter import Tk as tk
32
from tkinter import Toplevel, Button, Label, Entry, messagebox
43
import os
@@ -7,6 +6,7 @@
76

87
window = tk()
98

9+
1010
# Commands
1111
def new_file(filename, entry):
1212
entry.delete(0, 'end')
@@ -16,15 +16,19 @@ def new_file(filename, entry):
1616
def add_print(text, filename, entry):
1717
file = open(filename, 'a')
1818
entry.delete(0, 'end')
19+
entry.insert(0, "Text to show on console (use {variable_name} to show a variable")
1920
file.write(f"print(f\"{text}\")" + "\n")
2021
file.close()
2122
messagebox.showinfo("Add text on Console", "Text on Console added", parent=editwindow)
2223

23-
def add_variable(variable, filename, entry):
24+
def add_variable(name, value, filename, entry, entry2):
2425
file = open(filename, 'a')
2526
entry.delete(0, 'end')
26-
var = variable.split(",")[0]
27-
val = variable.split(",")[1].replace(" ", "")
27+
entry2.delete(0, 'end')
28+
entry.insert(0, 'Variable Value')
29+
entry2.insert(0, 'Variable Name')
30+
var = name
31+
val = value
2832
try:
2933
val = int(val)
3034
except:
@@ -36,20 +40,37 @@ def add_variable(variable, filename, entry):
3640
file.close()
3741
messagebox.showinfo("Add variable", "Variable added", parent=editwindow)
3842

39-
def add_input(variable, filename, entry):
43+
def add_input(name, value, filename, entry, entry2):
4044
file = open(filename, 'a')
4145
entry.delete(0, 'end')
42-
var = variable.split(",")[0]
43-
val = variable.split(",")[1].replace(" ", "")
44-
file.write(f"{var} = input(\"{val}\")" + "\n")
46+
entry2.delete(0, 'end')
47+
entry.insert(0, 'Input Variable Name')
48+
entry2.insert(0, 'Add Input text (use {variable_name} to show a variable)')
49+
var = name
50+
val = value
51+
file.write(f"{var} = input(f\"{val}\")" + "\n")
4552
file.close()
4653
messagebox.showinfo("Add input", "Input added", parent=editwindow)
4754

55+
# --------------------------------------- #
56+
# --------------------------------------- #
57+
# --------------------------------------- #
58+
59+
60+
# Callback
61+
def on_click(event):
62+
event.widget.selection_range(0, 'end')
63+
# --------------------------------------- #
64+
# --------------------------------------- #
65+
# --------------------------------------- #
66+
4867

68+
# On file Open
4969
def open_file(filename, entry):
5070
entry.delete(0, 'end')
5171
global window
5272
try:
73+
open(filename, 'r').close()
5374
global editwindow
5475
editwindow = Toplevel(window)
5576
editwindow.title(filename[:-3])
@@ -58,30 +79,58 @@ def open_file(filename, entry):
5879
editwindow.configure(background="#bebebe")
5980
Label(editwindow, text=filename[:-3], font=("Arial", 20), bg="#bebebe").pack()
6081
Label(editwindow, text="", bg="#bebebe").pack()
61-
Label(editwindow, text="Text to show on Console (use {variable_name} to show a variable)", bg="#bebebe").pack()
6282
textprint = Entry(editwindow)
83+
textprint.insert(0, "Text to show on console (use {variable_name} to show a variable")
6384
textprint.pack()
85+
textprint.bind("<Button-1>", on_click)
86+
textprint.bind("<FocusIn>", on_click)
6487
Button(editwindow, text="Add text on Console", command=lambda: add_print(textprint.get(), filename, textprint)).pack()
6588
Label(editwindow, text="", bg="#bebebe").pack()
66-
Label(editwindow, text="Create Variable (write: variable_name, variable value)", bg="#bebebe").pack()
67-
addvariable = Entry(editwindow)
68-
addvariable.pack()
69-
Button(editwindow, text="Add variable", command=lambda: add_variable(addvariable.get(), filename, addvariable)).pack()
89+
addvalue = Entry(editwindow)
90+
addvalue.insert(0, "Variable Value")
91+
addvalue.pack()
92+
addvalue.bind("<Button-1>", on_click)
93+
addvalue.bind("<FocusIn>", on_click)
94+
addname = Entry(editwindow)
95+
addname.insert(0, "Variable Name")
96+
addname.pack()
97+
addname.bind("<Button-1>", on_click)
98+
addname.bind("<FocusIn>", on_click)
99+
Button(editwindow, text="Add variable", command=lambda: add_variable(addname.get(), addvalue.get(), filename, addname, addvalue)).pack()
70100
Label(editwindow, text="", bg="#bebebe").pack()
71-
Label(editwindow, text="Add input Variable (write: variable_name, Input String)", bg="#bebebe").pack()
72101
addinput = Entry(editwindow)
102+
addinput.insert(0, "Input Variable Name")
73103
addinput.pack()
74-
Button(editwindow, text="Add input", command=lambda: add_input(addinput.get(), filename, addinput)).pack()
75-
except:
104+
addinput.bind("<Button-1>", on_click)
105+
addinput.bind("<FocusIn>", on_click)
106+
addinptext = Entry(editwindow)
107+
addinptext.insert(0, "Add Input text (use {variable_name} to show a variable)")
108+
addinptext.pack()
109+
addinptext.bind("<Button-1>", on_click)
110+
addinptext.bind("<FocusIn>", on_click)
111+
Button(editwindow, text="Add input", command=lambda: add_input(addinput.get(), addinptext.get(), filename, addinput, addinptext)).pack()
112+
except Exception as e:
113+
print(e)
76114
messagebox.showerror("Open File", "File not found")
77115

116+
# --------------------------------------- #
117+
# --------------------------------------- #
118+
# --------------------------------------- #
119+
120+
# Update Command
78121
def update(window):
79122
window.destroy()
80123
os.system("python3 update.py")
81124
exit()
82125

126+
# --------------------------------------- #
127+
# --------------------------------------- #
128+
# --------------------------------------- #
83129

130+
84131

132+
133+
# Main Window
85134
window.geometry("750x750")
86135
window.title("EzPython")
87136
window.resizable(False, False)
@@ -100,4 +149,8 @@ def update(window):
100149
Label(window, text="", bg="#bebebe").pack()
101150
Button(window, text="Update Software", command=lambda: update(window)).pack()
102151

103-
window.mainloop()
152+
window.mainloop()
153+
154+
# --------------------------------------- #
155+
# --------------------------------------- #
156+
# --------------------------------------- #

0 commit comments

Comments
 (0)