Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import filedialog, messagebox
- import subprocess
- import os
- def save_script():
- file_path = filedialog.asksaveasfilename(
- defaultextension=".py",
- filetypes=[("Python Files", "*.py"), ("All Files", "*.*")],
- )
- if file_path:
- try:
- with open(file_path, "w") as file:
- file.write(code_text.get("1.0", tk.END))
- messagebox.showinfo("Success", f"File saved: {file_path}")
- except Exception as e:
- messagebox.showerror("Error", f"Could not save file: {e}")
- def run_script():
- temp_file = "temp_script.py"
- try:
- with open(temp_file, "w") as file:
- file.write(code_text.get("1.0", tk.END))
- result = subprocess.run(
- ["python", temp_file],
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- text=True,
- )
- output_text.delete("1.0", tk.END)
- output_text.insert(tk.END, result.stdout if result.stdout else result.stderr)
- except Exception as e:
- output_text.insert(tk.END, f"Error: {e}")
- finally:
- if os.path.exists(temp_file):
- os.remove(temp_file)
- def clear_screen():
- code_text.delete("1.0", tk.END)
- output_text.delete("1.0", tk.END)
- # GUI Setup
- root = tk.Tk()
- root.title("Najeeb Python IDE with Auto-Correction")
- root.geometry("800x600")
- # Code Text Area
- code_frame = tk.Frame(root)
- code_frame.pack(fill="both", expand=True)
- # Scrollbars for Code Text
- code_scroll_y = tk.Scrollbar(code_frame, orient="vertical")
- code_scroll_y.pack(side="right", fill="y")
- code_scroll_x = tk.Scrollbar(code_frame, orient="horizontal")
- code_scroll_x.pack(side="bottom", fill="x")
- code_text = tk.Text(
- code_frame,
- wrap="none",
- bg="#2e2e2e",
- fg="#f8f8f2",
- insertbackground="#f8f8f2", # Cursor color
- font=("Courier New", 12),
- yscrollcommand=code_scroll_y.set,
- xscrollcommand=code_scroll_x.set
- )
- code_text.pack(fill="both", expand=True)
- code_scroll_y.config(command=code_text.yview)
- code_scroll_x.config(command=code_text.xview)
- # Buttons
- button_frame = tk.Frame(root, bg="#44475a")
- button_frame.pack(fill="x")
- save_button = tk.Button(button_frame, text="Save Script", command=save_script, bg="#6272a4", fg="white")
- save_button.pack(side="left", padx=5, pady=5)
- run_button = tk.Button(button_frame, text="Run Script", command=run_script, bg="#50fa7b", fg="black")
- run_button.pack(side="left", padx=5, pady=5)
- clear_button = tk.Button(button_frame, text="Clear Screen", command=clear_screen, bg="#ff5555", fg="white")
- clear_button.pack(side="left", padx=5, pady=5)
- # Output Text Area
- output_frame = tk.Frame(root)
- output_frame.pack(fill="both", expand=True)
- output_label = tk.Label(output_frame, text="Output:", bg="#282a36", fg="#f8f8f2")
- output_label.pack(anchor="w")
- # Scrollbars for Output Text
- output_scroll_y = tk.Scrollbar(output_frame, orient="vertical")
- output_scroll_y.pack(side="right", fill="y")
- output_scroll_x = tk.Scrollbar(output_frame, orient="horizontal")
- output_scroll_x.pack(side="bottom", fill="x")
- output_text = tk.Text(
- output_frame,
- wrap="none",
- bg="#1e1e1e",
- fg="#f8f8f2",
- insertbackground="#f8f8f2",
- font=("Courier New", 12),
- height=10,
- yscrollcommand=output_scroll_y.set,
- xscrollcommand=output_scroll_x.set
- )
- output_text.pack(fill="both", expand=True)
- output_scroll_y.config(command=output_text.yview)
- output_scroll_x.config(command=output_text.xview)
- # Run the GUI
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement