Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. from tkinter import *
  2. from tkinter.filedialog import *
  3. import fileinput
  4.  
  5. width = 400
  6. height = 300
  7.  
  8.  
  9. class Window(object):
  10.     def __init__(self, root, w, h):
  11.         self.root = root
  12.         frame = Frame(self.root, width=w, height=h)
  13.         frame.grid(row=0, column=0, rowspan=3, columnspan=3)
  14.  
  15.         self.menu1 = Menu(root)
  16.         self.root.config(menu=self.menu1)
  17.  
  18.         self.txt = Text(root, width=79, height=30, font='14')
  19.         self.txt.grid(row=0, column=0)
  20.         self.openf = Button(text='Open', command=self.openfile)
  21.         self.openf.grid(row=1, column=0)
  22.         self.savef = Button(text='Save', command=self.savefileas)
  23.         self.savef.grid(row=1, column=1)
  24.         self.runf = Button(text='Run', command=self.runfile)
  25.         self.runf.grid(row=1, column=2)
  26.  
  27.         self.txt.delete('1.0', END)
  28.  
  29.     def openfile(self):
  30.         op = askopenfilename()
  31.         self.txt.delete('1.0', END)
  32.         for l in fileinput.input(op):
  33.             self.txt.insert(END, l)
  34.  
  35.     def savefileas(self):
  36.         sa = asksaveasfilename()
  37.         letter = self.txt.get(1.0, END)
  38.         f = open(sa, 'w')
  39.         f.write(letter)
  40.         f.close()
  41.  
  42.     def runfile(self):
  43.         src = askopenfilename()
  44.         str = ""
  45.         for ln in fileinput.input(src):
  46.             str += ln
  47.         obj = compile(str, 'string', 'exec')
  48.         exec(obj)
  49.  
  50. if __name__ == '__main__':
  51.     root = Tk()
  52.     window1 = Window(root, width, height)
  53.     root.title('prototype1')
  54.     root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement