1

I am creating a code editor and I want to create terminal for my code editor I have already created one with the help of tkterminal but it is not works as other python shell work in other code editors basically main problem is that my terminal that I have created with the help of tkterminal I unable to input() code this is my code(not full code short version of real one):

from tkinter import*
from tkinter.filedialog import askopenfilename, asksaveasfilename
from tkterminal import Terminal
def Open(event=None):
    global file 
    file = askopenfilename(defaultextension=".py",filetypes=[("Python","*.py")])
    if file == "":
        file = None
    else:
        editor.delete(1.0,END)
        with open(file,"r") as f:
            editor.insert(1.0,f.read())
def save(event=None):
    global file 
    if file == "":
        saveas()
    else:
        with open(file,"w") as f:
            f.write(editor.get(1.0,END))
def saveas(event=None):
    global file 
    file = asksaveasfilename(defaultextension=".py",filetypes=[("Python","*.py")])
    if file == "":
        file = None
    else:
        with open(file,"w") as f:
            f.write(editor.get(1.0,END))
def run(event=None):
    global file 
    if file == "":
        pass 
    else:
        command = f'python "{file}"'
        output.run_command(command,give_input=None)
    return "break"
root = Tk()
file = ""
editor = Text()
editor.pack()
output = Terminal(height=15)
output.shell = True
output.basename = "Code>>"
output.pack()
editor.bind("<Control-o>",Open)
editor.bind("<Control-s>",save)
editor.bind("<Control-Alt-s>",saveas)
editor.bind("<Shift-Return>",run)
root.mainloop()

this is what I am creating:- enter image description here

1
  • 2
    I think the problem is that the tkterminal module is designed to work like a cmd shell, not as a python console like it seems you want. It's possible that this kind of solution is what you are looking for. Commented Apr 17, 2022 at 16:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.