1

My display class should run inputs as python code. But I don't know how to add exec code to my Text. For eaxmple if I type print("Hello WORLD")and press button in shell is output Hello WORLD but in Text not. Any ideas how I can get output to my Text output?

from tkinter import *
import sys
import code

class Display:

    def __init__(self):

        #window
        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()

        #console
        self.konzola = code.InteractiveInterpreter()


    def vypis(self):
        compiledText = self.kompiluj(self.entry.get())
        self.output.insert(END,str(exec(self.entry.get())))

    def kompiluj(self,code):
        return self.konzola.compile(code,'','exec')

    def loop(self):
        self.frame.mainloop()

if __name__ == '__main__':
    Display().loop()
dsv_dsv
  • 49
  • 1
  • 8

0 Answers0