Sahan RanasingheCode Junior
පයිතන් වලින් IDE එකක් හදමු :) Create Your Own IDE
ඔනැම IDE එකක් open කර මෙම කෝඩ් එක type කරන්න.
from tkinter import * from tkinter.filedialog import asksaveasfilename, askopenfilename import subprocess compiler = Tk() compiler.title('My IDE') file_path = '' def set_file_path(path): global file_path file_path = path def open_file(): path = askopenfilename(filetypes=[('Python Files', '*.py')]) with open(path, 'r') as file: code = file.read() editor.delete('1.0', END) editor.insert('1.0', code) set_file_path(path) def save_as(): if file_path == '': path = asksaveasfilename(filetypes=[('Python Files', '*.py')]) else: path = file_path with open(path, 'w') as file: code = editor.get('1.0', END) file.write(code) set_file_path(path) def run(): if file_path == '': save_prompt = Toplevel() text = Label(save_prompt, text='Please save your code') text.pack() return command = f'python {file_path}' process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) output, error = process.communicate() code_output.insert('1.0', output) code_output.insert('1.0', error) menu_bar = Menu(compiler) file_menu = Menu(menu_bar, tearoff=0) file_menu.add_command(label='Open', command=open_file) file_menu.add_command(label='Save', command=save_as) file_menu.add_command(label='Save As', command=save_as) file_menu.add_command(label='Exit', command=exit) menu_bar.add_cascade(label='File', menu=file_menu) run_bar = Menu(menu_bar, tearoff=0) run_bar.add_command(label='Run', command=run) menu_bar.add_cascade(label='Run', menu=run_bar) compiler.config(menu=menu_bar) editor = Text() editor.pack() code_output = Text(height=10) code_output.pack() compiler.mainloop()
දැන් රන් කරන්න 🙂
Share
👌
It has an error
error ekak enawane
Traceback (most recent call last):
File “C:\Users\sahan\AppData\Local\Programs\Thonny\lib\ast.py”, line 35, in parse
return compile(source, filename, mode, PyCF_ONLY_AST)
File “C:\Users\sahan\f.py”, line 10
global file_path
^
IndentationError: expected an indented block
mekada eror eka
me code eka eror ekak enawa thama sorry mama hadannam
from tkinter import *
from tkinter.filedialog import asksaveasfilename, askopenfilename
import subprocess
compiler = Tk()
compiler.title(‘My Fantastic IDE’)
file_path = ”
def set_file_path(path):
global file_path
file_path = path
def open_file():
path = askopenfilename(filetypes=[(‘Python Files’, ‘*.py’)])
with open(path, ‘r’) as file:
code = file.read()
editor.delete(‘1.0’, END)
editor.insert(‘1.0’, code)
set_file_path(path)
def save_as():
if file_path == ”:
path = asksaveasfilename(filetypes=[(‘Python Files’, ‘*.py’)])
else:
path = file_path
with open(path, ‘w’) as file:
code = editor.get(‘1.0′, END)
file.write(code)
set_file_path(path)
def run():
if file_path == ”:
save_prompt = Toplevel()
text = Label(save_prompt, text=’Please save your code’)
text.pack()
return
command = f’python {file_path}’
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
output, error = process.communicate()
code_output.insert(‘1.0’, output)
code_output.insert(‘1.0′, error)
menu_bar = Menu(compiler)
file_menu = Menu(menu_bar, tearoff=0)
file_menu.add_command(label=’Open’, command=open_file)
file_menu.add_command(label=’Save’, command=save_as)
file_menu.add_command(label=’Save As’, command=save_as)
file_menu.add_command(label=’Exit’, command=exit)
menu_bar.add_cascade(label=’File’, menu=file_menu)
run_bar = Menu(menu_bar, tearoff=0)
run_bar.add_command(label=’Run’, command=run)
menu_bar.add_cascade(label=’Run’, menu=run_bar)
compiler.config(menu=menu_bar)
editor = Text()
editor.pack()
code_output = Text(height=10)
code_output.pack()
compiler.mainloop()
මේ කොඩ් එක ගහන්න එරර් එකක් ආවනම්
from tkinter import *
from tkinter.filedialog import asksaveasfilename, askopenfilename
import subprocess
compiler = Tk()
compiler.title(‘My Fantastic IDE’)
file_path = ”
def set_file_path(path):
global file_path
file_path = path
def open_file():
path = askopenfilename(filetypes=[(‘Python Files’, ‘*.py’)])
with open(path, ‘r’) as file:
code = file.read()
editor.delete(‘1.0’, END)
editor.insert(‘1.0’, code)
set_file_path(path)
def save_as():
if file_path == ”:
path = asksaveasfilename(filetypes=[(‘Python Files’, ‘*.py’)])
else:
path = file_path
with open(path, ‘w’) as file:
code = editor.get(‘1.0′, END)
file.write(code)
set_file_path(path)
def run():
if file_path == ”:
save_prompt = Toplevel()
text = Label(save_prompt, text=’Please save your code’)
text.pack()
return
command = f’python {file_path}’
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
output, error = process.communicate()
code_output.insert(‘1.0’, output)
code_output.insert(‘1.0′, error)
menu_bar = Menu(compiler)
file_menu = Menu(menu_bar, tearoff=0)
file_menu.add_command(label=’Open’, command=open_file)
file_menu.add_command(label=’Save’, command=save_as)
file_menu.add_command(label=’Save As’, command=save_as)
file_menu.add_command(label=’Exit’, command=exit)
menu_bar.add_cascade(label=’File’, menu=file_menu)
run_bar = Menu(menu_bar, tearoff=0)
run_bar.add_command(label=’Run’, command=run)
menu_bar.add_cascade(label=’Run’, menu=run_bar)
compiler.config(menu=menu_bar)
editor = Text()
editor.pack()
code_output = Text(height=10)
code_output.pack()
compiler.mainloop()
from tkinter import *
from tkinter.filedialog import asksaveasfilename, askopenfilename
import subprocess
compiler = Tk()
compiler.title(‘My Fantastic IDE’)
file_path = ”
def set_file_path(path):
global file_path
file_path = path
def open_file():
path = askopenfilename(filetypes=[(‘Python Files’, ‘*.py’)])
with open(path, ‘r’) as file:
code = file.read()
editor.delete(‘1.0’, END)
editor.insert(‘1.0’, code)
set_file_path(path)
def save_as():
if file_path == ”:
path = asksaveasfilename(filetypes=[(‘Python Files’, ‘*.py’)])
else:
path = file_path
with open(path, ‘w’) as file:
code = editor.get(‘1.0′, END)
file.write(code)
set_file_path(path)
def run():
if file_path == ”:
save_prompt = Toplevel()
text = Label(save_prompt, text=’Please save your code’)
text.pack()
return
command = f’python {file_path}’
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
output, error = process.communicate()
code_output.insert(‘1.0’, output)
code_output.insert(‘1.0′, error)
menu_bar = Menu(compiler)
file_menu = Menu(menu_bar, tearoff=0)
file_menu.add_command(label=’Open’, command=open_file)
file_menu.add_command(label=’Save’, command=save_as)
file_menu.add_command(label=’Save As’, command=save_as)
file_menu.add_command(label=’Exit’, command=exit)
menu_bar.add_cascade(label=’File’, menu=file_menu)
run_bar = Menu(menu_bar, tearoff=0)
run_bar.add_command(label=’Run’, command=run)
menu_bar.add_cascade(label=’Run’, menu=run_bar)
compiler.config(menu=menu_bar)
editor = Text()
editor.pack()
code_output = Text(height=10)
code_output.pack()
compiler.mainloop()
It has an error 😒😒😒😒😒😒