I made a little py editor because I didn't want to go to all the troble of installing an idle, but I didn't like notepad either. Here it is!
PyEditor1.6
JasonHippy commented: A great start, definitely something that can be built upon! +9
import PyEditorErrors as errors
import os, sys
if sys.hexversion >= 0x030000F0:
runningPython3 = True
else:
runningPython3 = False
if runningPython3:
import tkinter.filedialog as tk_FileDialog
from tkinter import*
else:
from Tkinter import*
import tkFileDialog as tk_FileDialog
class PyEditor:
def doNew(self):
self.askRoot = Tk()
self.askRoot.geometry("300x200")
self.askRoot.minsize(width=300, height=200)
self.askRoot.title("Create New File")
self.askFileLabel = Label(self.askRoot, text="Enter the file name.")
self.askFileName = Entry(self.askRoot)
self.askFileNameDoneButton = Button(self.askRoot, text="Done", command=self.doFileNameDone)
self.askFileLabel.pack()
self.askFileName.pack()
self.askFileNameDoneButton.pack()
def doFileNameDone(self):
if str(self.askFileName) != '':
file = open((self.currentDir+"/Programs/"+self.askFileName.get()), "a")
self.filename = file.name
file.close()
self.windowText.delete(0.0, END)
self.windowText.insert(0.0, "#")
self.windowText.insert(END, self.filename)
self.askRoot.destroy()
else:
errors.nothingError("Nothing Entered")
self.askRoot.destroy()
def doSave(self):
if self.filename != "":
file = open(self.filename, "w")
currentContents = self.windowText.get(0.0, END)
file.write(currentContents)
file.close()
else:
errors.noFileError("File Not Found")
def doOpen(self):
file = tk_FileDialog.askopenfile(mode='r', title="Open File", defaultextension=".py", initialdir=self.currentDir+"/Programs/")
if file != None:
filecontents = file.read()
self.windowText.delete(0.0, END)
self.windowText.insert(END, filecontents)
self.filename = file.name
file.close()
else:
print("Nothing found. Command cancled.")
def doRun(self):
file = tk_FileDialog.askopenfile(mode='r', title="Run File", defaultextension=".py", initialdir=self.currentDir+"/Programs/")
print("\nRunning",file.name+".\n")
os.system('c:\\Python34\\python "'+file.name+'"')
def doRunCurrent(self):
if self.filename != "":
print("\nRunning",self.filename+".\n")
os.system('c:\\Python34\\python "'+self.filename+'"')
else:
errors.noFileError("File Not Found")
def __init__(self):
if sys.platform.startswith("darwin"):
osType = "Mac"
else:
osType = "Other"
self.filename = ""
self.currentDir = os.getcwd()
self.root = Tk()
self.root.geometry("700x550")
self.root.minsize(width=700, height=550)
self.root.title("PyEditor 1.6")
self.windowText = Text(self.root, width=200, height=150)
self.windowText.pack()
menubar = Menu(self.root, tearoff=0)
filemenu = Menu(menubar, tearoff=0)
runmenu = Menu(menubar, tearoff=0)
if osType == "Other":
filemenu.add_command(label="New", command=self.doNew, accelerator="Ctrl+N")
filemenu.add_command(label="Save", command=self.doSave, accelerator="Ctrl+S")
filemenu.add_command(label="Open", command=self.doOpen, accelerator="Ctrl+O")
filemenu.add_separator()
filemenu.add_command(label="Exit", command=self.root.destroy, accelerator="Ctrl+E")
runmenu.add_command(label="Run", command=self.doRun, accelerator="Ctrl+R")
runmenu.add_command(label="Run Current", command=self.doRunCurrent, accelerator="Ctrl+Shift+R")
elif osType == "Mac":
filemenu.add_command(label="New", command=self.doNew, accelerator="Command+N")
filemenu.add_command(label="Save", command=self.doSave, accelerator="Command+S")
filemenu.add_command(label="Open", command=self.doOpen, accelerator="Command+O")
filemenu.add_separator()
filemenu.add_command(label="Exit", command=self.root.destroy, accelerator="Command+E")
runmenu.add_command(label="Run Program", command=self.doRun, accelerator="Command+R")
runmenu.add_command(label="Run Current", command=self.doRunCurrent, accelerator="Command+Shift+R")
menubar.add_cascade(menu=filemenu, label="File")
menubar.add_cascade(menu=runmenu, label="Run")
self.root.config(menu=menubar)
self.windowText.insert(END, "Select a menu or click help to start.")
if __name__ == "__main__":
app = PyEditor()
app.root.mainloop()
JasonHippy 739 Practically a Master Poster
DragonMastur 23 Light Poster
DragonMastur 23 Light Poster
DragonMastur 23 Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.