我想用Python tkinter制作一个增强版的命令提示符,使用subprocess.getoutput()获取返回值。
但是当我输入date等需要进一步操作的命令时,程序就会失去响应
请问这是为什么?如何解决?谢谢!
这是我的源码:
from tkinter import *
import subprocess
def cmd(commands):
m.insert('end-1c linestart', '>>>')
commands = m.get('end-1c linestart+3c', END)
result = subprocess.getoutput(commands)
s.delete(1.0, END)
s.insert(INSERT, '\n' + result)
win = Tk()
win.title('Py!CMD')
s = Text(win, font=40)
s.place(relheight=1, relwidth=0.6, relx=0.4, rely=0)
m = Text(win, font=40)
m.place(relheight=1, relwidth=0.4, relx=0, rely=0)
m.bind('' , cmd)
win.mainloop()
把报错复制出来发给我
你可以参考下这篇文章:python subprocess模块的使用