开发者

build cmd into Tkinter window

开发者 https://www.devze.com 2023-03-05 15:41 出处:网络
Hi i was wondering if you could have the comand prompt box pop into the Tkinter window when you start the program? Some thing lik开发者_Go百科e:

Hi i was wondering if you could have the comand prompt box pop into the Tkinter window when you start the program? Some thing lik开发者_Go百科e:

from Tkinter import *
admin = Tk()
cmd = Cmd(admin)
cmd.pack()
admin.mainloop()

I'm on windows


http://tkinter.unpythonic.net/wiki/CmdTkHere is what you want, this is not just opening a cmd window. its embedding cmd.exe into a Tkinter.Frame. And a note here if you rename the python script to ".pyw" extension, the console will be hidden. Except for in a virtual environment's.


I don't believe there is any built in console widget. It may be possible to whip up a custom one using the Tkinter Text widget. However, that would take a bit of effort/time.

Another possible option is simply have your program launch command prompt.

Two different ways to launch command prompt on a Windows machine.

import subprocess, os

subprocess.Popen('cmd.exe')

os.system("cmd.exe") 

EDIT:

Unforunetly I don't believe there is any built in widget like that. However I thought of another possible solution, check out the code for the IDLE GUI, it has a console and the GUI portion is entirley written using Tkinter. So you may be able to utelize that code.

0

精彩评论

暂无评论...
验证码 换一张
取 消