Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from tkinter.filedialog import asksaveasfilename, askopenfilename
- import subprocess
- compiler = Tk()
- compiler.title('Najeeb Python IDE')
- compiler.geometry('1000x600') # Adjust window size to 1000x700
- file_path = ''
- def set_file_path(path):
- global file_path
- file_path = path
- def open_file():
- path = askopenfilename(filetypes=[('Python Files', '*.py'), ("All Files", "*.*")])
- if path:
- 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'), ("All Files", "*.*")])
- else:
- path = file_path
- if 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.delete('1.0', END) # Clear previous output
- code_output.insert('1.0', output)
- code_output.insert('1.0', error)
- # Set up menu bar
- 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)
- # Create editor field with a scrollbar
- editor_frame = Frame(compiler)
- editor_frame.pack(fill=BOTH, expand=True)
- editor_scrollbar = Scrollbar(editor_frame)
- editor_scrollbar.pack(side=RIGHT, fill=Y)
- editor = Text(editor_frame, font=('Times New Roman', 16), height=20, yscrollcommand=editor_scrollbar.set)
- editor.pack(fill=BOTH, expand=True)
- editor_scrollbar.config(command=editor.yview)
- # Create output field with a scrollbar
- output_frame = Frame(compiler)
- output_frame.pack(fill=BOTH, expand=True)
- output_scrollbar = Scrollbar(output_frame)
- output_scrollbar.pack(side=RIGHT, fill=Y)
- code_output = Text(output_frame, bg="black", fg="white", font=('Times New Roman', 12), height=10, yscrollcommand=output_scrollbar.set)
- code_output.pack(fill=BOTH, expand=True)
- output_scrollbar.config(command=code_output.yview)
- compiler.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement