I am creating an code editor but when use input() code in inside my own code editor and try to run my terminal shows this error
error:-
Enter any number
Traceback (most recent call last):
File "D:\coding notes\pytho project\editor\new.py", line 1, in <module>
T = int(input("Enter any number\n"))
EOFError: EOF when reading a line
What modification I have to do So that my run function works correctly
this is my run function:-
def Run(event=None):
global file
if file == "":
pass
else:
command = f'python "{file}"'
run_file = subprocess.Popen(command,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
Output, error = run_file.communicate()
output.insert(END,f"{file}>>\n")
output.insert(END,Output)
output.insert(END,error)
full code(not full code short version of real code):-
import subprocess
from tkinter import*
from tkinter.filedialog import askopenfilename
def Open(event=None):
global file
file = askopenfilename(defaultextension=".py",filetypes=[("Python Files","*.py")])
if file == "":
file = None
else:
editor.delete(1.0,END)
with open(file,"r") as f:
editor.insert(1.0,f.read())
def Run(event=None):
global file
if file == "":
pass
else:
command = f'python "{file}"'
run_file = subprocess.Popen(command,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
Output, error = run_file.communicate()
output.insert(END,f"{file}>>\n")
output.insert(END,Output)
output.insert(END,error)
root = Tk()
file = ""
editor = Text()
editor.pack()
output = Text(height=15)
output.pack()
root.bind("<Control-o>",Open)
root.bind("<Shift-Return>",Run)
root.mainloop()
You can see the error in this image, this is the code editor that I have created:-