Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
from tkinter import *
import os
import sys
class Application(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.master = master
self.master.title('Interpreter')
self.master.resizable(width=False, height=False)
self.master.geometry('500x500')
self.create_widgets()
def create_widgets(self):
input_frame = Frame(self.master)
input_frame.grid(row=0, column=0, sticky=W)
self.input_text = Text(input_frame, width=72, height=20)
self.input_text.grid(row=0, column=0)
output_frame = Frame(self.master)
output_frame.grid(row=1, column=0)
self.output_text = Text(output_frame, height=10)
self.output_text.grid(row=0, column=0)
buttons_frame = Frame(self.master)
buttons_frame.grid(row=2, column=0)
run_button = Button(buttons_frame, text='Run', command=self.run)
run_button.grid(row=0, column=0)
def run(self):
text = self.input_text.get('1.0', 'end-1c')
text = text.split('\n')
for i, x in enumerate(text):
text[i] = str(x).replace('\t', '')
if '' is x:
continue
sys.stdout = open(os.path.expanduser('~/Desktop/output.txt'), 'a')
exec(str(x))
sys.stdout.flush()
with open(os.path.expanduser('~/Desktop/output.txt'), 'r') as output_file:
for line in output_file:
self.output_text.insert(END, line)
def main():
root = Tk()
Application(root)
root.mainloop()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment