我尝试像python控制台一样制作Tk窗口。但我的问题是当多行代码到来时。如果输入是多行的,我可以compille_command()
和runcode()
:例如,如果为True:print(某物)或i为范围(x)
from tkinter import *
import code,skuska
class Display:
def __init__(self):
self.frame = Tk()
self.entry = Entry(self.frame)
self.entry.pack()
self.button = Button(self.frame,text="DoIt", command=self.vypis)
self.button.pack()
self.output = Text(self.frame)
self.output.pack()
self.konzola = code.InteractiveInterpreter()
self.out = skuska.Capturing()
def vypis(self):
compiledText = self.kompiluj(self.entry.get())
with skuska.Capturing() as self.out:
self.konzola.runcode(compiledText)
self.output.insert(END,str(self.out)+'\n')
print('OUTPUT IS :' , self.out)
def kompiluj(self,kod):
return code.compile_command(kod)
def loop(self):
self.frame.mainloop()
if __name__ == '__main__':
Display().loop()