将 cmd 构建到 Tkinter 窗口中 [英] build cmd into Tkinter window
问题描述
我想知道您是否可以在启动程序时将命令提示框弹出到 Tkinter 窗口中?比如:
Hi i was wondering if you could have the comand prompt box pop into the Tkinter window when you start the program? Some thing like:
from Tkinter import *
admin = Tk()
cmd = Cmd(admin)
cmd.pack()
admin.mainloop()
我在窗户上
推荐答案
我不相信有任何内置的控制台小部件.可以使用 Tkinter Text 小部件创建一个自定义的.但是,这需要一些努力/时间.
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.
在 Windows 机器上启动命令提示符的两种不同方式.
Two different ways to launch command prompt on a Windows machine.
import subprocess, os
subprocess.Popen('cmd.exe')
os.system("cmd.exe")
不幸的是,我不相信有任何内置的小部件.但是我想到了另一种可能的解决方案,查看 IDLE GUI 的代码,它有控制台和 GUI 部分完全使用 Tkinter 编写.因此,您可以使用该代码.
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.
这篇关于将 cmd 构建到 Tkinter 窗口中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!