Tkinter GUI에서 명령줄의 변경 사항을 실시간으로 표시하려고 합니다. GUI를 만들고 터미널을 여기에 통합했지만 버튼을 터미널에 바인딩할 수 없습니다. 내 코드는 다음과 같습니다.
import Tkinter
from Tkinter import *
import subprocess
import os
from os import system as cmd
WINDOW_SIZE = "600x400"
top = Tkinter.Tk()
top.geometry(WINDOW_SIZE)
def helloCallBack():
print "Below is the output from the shell script in terminal"
subprocess.call('perl /projects/tfs/users/$USER/scripts_coverage.pl', shell=True)
def BasicCovTests():
print "Below is the output from the shell script in terminal"
subprocess.call('perl /projects/tfs/users/$USER/basic_coverage_tests.pl', shell=True)
def FullCovTests():
print "Below is the output from the shell script in terminal"
subprocess.call('perl /projects/tfs/users/$USER/basic_coverage_tests.pl', shell=True)
Scripts_coverage = Tkinter.Button(top, text ="Scripts Coverage", command = helloCallBack)
Scripts_coverage.pack()
Basic_coverage_tests = Tkinter.Button(top, text ="Basic Coverage Tests", command = BasicCovTests)
Basic_coverage_tests.pack()
Full_coverage_tests = Tkinter.Button(top, text ="Full Coverage Tests", command = FullCovTests)
Full_coverage_tests.pack()
termf = Frame(top, height=100, width=500)
termf.pack(fill=BOTH, expand=YES)
wid = termf.winfo_id()
os.system('xterm -into %d -geometry 100x20 -sb &' % wid)
def send_entry_to_terminal(*args):
"""*args needed since callback may be called from no arg (button)
or one arg (entry)
"""
cmd("%s" % (BasicCovTests))
top.mainloop()
승리하고 싶습니다. 버튼을 클릭하면 터미널에 명령이 인쇄되는 것을 볼 수 있습니다.
답변1
나는 이것이 늦은 답변이라는 것을 알고 있지만 해결책이 있습니다 :)
사용하는 대신
subprocess.call('perl /projects/tfs/users/$USER/scripts_coverage.pl', shell=True)
나는 이것을 사용했다
os.system('xterm -into %d -geometry 100x20 -sb -e command &' % wid)