Advertisement
Najeebsk

PYIDE.pyw

Nov 23rd, 2024
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.57 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import filedialog, messagebox
  3. import subprocess
  4. import os
  5.  
  6. def save_script():
  7.     file_path = filedialog.asksaveasfilename(
  8.         defaultextension=".py",
  9.         filetypes=[("Python Files", "*.py"), ("All Files", "*.*")],
  10.     )
  11.     if file_path:
  12.         try:
  13.             with open(file_path, "w") as file:
  14.                 file.write(code_text.get("1.0", tk.END))
  15.             messagebox.showinfo("Success", f"File saved: {file_path}")
  16.         except Exception as e:
  17.             messagebox.showerror("Error", f"Could not save file: {e}")
  18.  
  19. def run_script():
  20.     temp_file = "temp_script.py"
  21.     try:
  22.         with open(temp_file, "w") as file:
  23.             file.write(code_text.get("1.0", tk.END))
  24.        
  25.         result = subprocess.run(
  26.             ["python", temp_file],
  27.             stdout=subprocess.PIPE,
  28.             stderr=subprocess.PIPE,
  29.             text=True,
  30.         )
  31.         output_text.delete("1.0", tk.END)
  32.         output_text.insert(tk.END, result.stdout if result.stdout else result.stderr)
  33.     except Exception as e:
  34.         output_text.insert(tk.END, f"Error: {e}")
  35.     finally:
  36.         if os.path.exists(temp_file):
  37.             os.remove(temp_file)
  38.  
  39. def clear_screen():
  40.     code_text.delete("1.0", tk.END)
  41.     output_text.delete("1.0", tk.END)
  42.  
  43. # GUI Setup
  44. root = tk.Tk()
  45. root.title("Najeeb Python IDE with Auto-Correction")
  46. root.geometry("800x600")
  47.  
  48. # Code Text Area
  49. code_frame = tk.Frame(root)
  50. code_frame.pack(fill="both", expand=True)
  51.  
  52. # Scrollbars for Code Text
  53. code_scroll_y = tk.Scrollbar(code_frame, orient="vertical")
  54. code_scroll_y.pack(side="right", fill="y")
  55.  
  56. code_scroll_x = tk.Scrollbar(code_frame, orient="horizontal")
  57. code_scroll_x.pack(side="bottom", fill="x")
  58.  
  59. code_text = tk.Text(
  60.     code_frame,
  61.     wrap="none",
  62.     bg="#2e2e2e",
  63.     fg="#f8f8f2",
  64.     insertbackground="#f8f8f2",  # Cursor color
  65.     font=("Courier New", 12),
  66.     yscrollcommand=code_scroll_y.set,
  67.     xscrollcommand=code_scroll_x.set
  68. )
  69. code_text.pack(fill="both", expand=True)
  70.  
  71. code_scroll_y.config(command=code_text.yview)
  72. code_scroll_x.config(command=code_text.xview)
  73.  
  74. # Buttons
  75. button_frame = tk.Frame(root, bg="#44475a")
  76. button_frame.pack(fill="x")
  77.  
  78. save_button = tk.Button(button_frame, text="Save Script", command=save_script, bg="#6272a4", fg="white")
  79. save_button.pack(side="left", padx=5, pady=5)
  80.  
  81. run_button = tk.Button(button_frame, text="Run Script", command=run_script, bg="#50fa7b", fg="black")
  82. run_button.pack(side="left", padx=5, pady=5)
  83.  
  84. clear_button = tk.Button(button_frame, text="Clear Screen", command=clear_screen, bg="#ff5555", fg="white")
  85. clear_button.pack(side="left", padx=5, pady=5)
  86.  
  87. # Output Text Area
  88. output_frame = tk.Frame(root)
  89. output_frame.pack(fill="both", expand=True)
  90.  
  91. output_label = tk.Label(output_frame, text="Output:", bg="#282a36", fg="#f8f8f2")
  92. output_label.pack(anchor="w")
  93.  
  94. # Scrollbars for Output Text
  95. output_scroll_y = tk.Scrollbar(output_frame, orient="vertical")
  96. output_scroll_y.pack(side="right", fill="y")
  97.  
  98. output_scroll_x = tk.Scrollbar(output_frame, orient="horizontal")
  99. output_scroll_x.pack(side="bottom", fill="x")
  100.  
  101. output_text = tk.Text(
  102.     output_frame,
  103.     wrap="none",
  104.     bg="#1e1e1e",
  105.     fg="#f8f8f2",
  106.     insertbackground="#f8f8f2",
  107.     font=("Courier New", 12),
  108.     height=10,
  109.     yscrollcommand=output_scroll_y.set,
  110.     xscrollcommand=output_scroll_x.set
  111. )
  112. output_text.pack(fill="both", expand=True)
  113.  
  114. output_scroll_y.config(command=output_text.yview)
  115. output_scroll_x.config(command=output_text.xview)
  116.  
  117. # Run the GUI
  118. root.mainloop()
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement