2

I was looking for a way to embed python shell inside tkinter, and had no luck finding.

I have searched this up and saw this answer: https://stackoverflow.com/a/30222807/4934971

Which contains:

#!/usr/bin/python

from Tkinter import *
import os

root = Tk()
termf = Frame(root, width = 400, height = 200)

termf.pack(fill=BOTH, expand=YES)
wid = termf.winfo_id()
os.system('xterm -into %d -geometry 80x20 -sb -e python &' % wid)

root.mainloop()

But running it on windows will only return an error because there's no xterm. Though I would like to know of there is any way this can be done in windows.

Community
  • 1
  • 1
Ako Cruz
  • 343
  • 1
  • 2
  • 12
  • 1
    I guess you'd have to install a terminal emulator which [works on Windows](http://www.slant.co/topics/1552/~what-are-the-best-terminal-emulators-for-windows) and launch that instead of xterm. – implmentor Aug 17 '15 at 13:54
  • 2
    Are you wanting a terminal emulator as described in the title, or a python shell as described in the question? Those are two different things. – Bryan Oakley Aug 17 '15 at 14:14
  • @BryanOakley im sorry, a python shell. – Ako Cruz Aug 17 '15 at 15:00
  • @bleakgadfly any recommendation for embedding to tkinter if possible? but still, thank you very much for your reply! – Ako Cruz Aug 17 '15 at 15:04
  • 1
    Have you seen http://stackoverflow.com/questions/5597836/how-can-i-embedcreate-an-interactive-python-shell-in-my-python-program ? – Eric Levieil Aug 17 '15 at 15:16
  • @EricLevieil looks interesting! ill look it up thoroughly. Thank you very much! – Ako Cruz Aug 17 '15 at 15:59

1 Answers1

0

Tkinter does not make it easy to create a python shell within a window; however, if you did not save your script as [.pyw], then upon executing the program you will get both a Tkinter window, and a console window.

Any commands dictated in normal python code, such as print, will print to the console. The closest you are going to get is by creating a window that allows actions to happen in the console window.