import sys
from tkinter import *
import time
class main:
def __init__(self, text=""):
self.root = Tk()
self.root.title("python editor")
self.Text = text
self.window = self.text_window(self, self.Text)
self.root.mainloop()
class text_window:
def __init__(self, master, text):
self.master = master
self.textBox = Text(master.root)
self.textBox.insert(END, text)
self.textBox.grid(row=0, sticky=NSEW, columnspan=2)
self.master.root.rowconfigure(0, weight=1)
self.master.root.columnconfigure(0, weight=1)
self.buttonOK = Button(master.root, text="run",
command=self.get_text)
self.buttonOK.bind('Enter',self.get_text)
self.buttonOK.grid(row=1, column=2)
self.buttonNO=Button(master.root, text="close window",command=self.abort)
self.buttonNO.grid(row=1, column=1)
def get_text(self):
text= self.textBox.get(1.0, END)
if ">>> " in text:
qwerty=str(exec(text[4:]))
return qwerty
else:
qwerty=exec(text)
return qwerty
def abort(self):
sys.exit()
def get_main(text=""):
m = main(text)
output = m.Text
return output
get_main(">>> ")
I am trying to make a tkinter window that will run multiline code like IDLE. Everything other than loops work.
If I try to run an infinite loop (While
loop), and tried to abort it, it doesn't abort and just runs it forever until the window says (not responding).
I am using python 3.6 on windows 10.