Skip to content

How to add a console to a tkinter window

I want a way to add a console to a tkinter window or redirect the output of the eval or exec functions to the maybe a uneditable text widget in tkinter. Also I want it so the code does not have to be saved first to get executed, I want it to be executed nevertheless. I have already viewed a few similar asked questions but have not understood what they do properly enough to implement it as I want myself to be able to customize it once I make it and not just copy down the code for it and use it. The official ipython console docs tell that ipython support qt and pyside but does not mention about tkinter(atleast till where I have seen).

Answer

I’ve tried this before. I found for myself the best way to do this is with a ListBox.

Here is a resource relating to ListBox: Python Tkinter Listbox

When I want to log something, I use the ListBox.insert(...) command so it gets stored in the list.

You can resize this list to either fit on the side or bottom of your program, just like a console.