如何传递参数以从Tkinter调用Shell脚本?

时间:2019-05-22 13:29:14

标签: python-3.x tkinter subprocess

我想使用来自tkinter gui的参数执行shell脚本。我已经编写了文本框的代码供用户输入,当按下按钮时,它会执行脚本并作为测试打印文本框的值。

但是,我希望在按下按钮时将文本框值传递给Shell脚本。我怎么打这个电话?请帮忙。

下面的代码是从我从本网站收集的各种代码示例中组合而成的。.感谢所有提供此代码的人。...

问题所在:Date.sh应该将inputvalue作为参数... Date.sh只是打印日期...在这里没什么好看的...

subprocess.call(['./date.sh inputValue']) #shell=True)

我正在python3中运行它

from tkinter import *
import subprocess

root=Tk()

#subprocess.call(['./verify_script.sh', var.get()])
def retrieve_input():
    inputValue=textBox.get("1.0","end-1c")
    print(inputValue)

textBox=Text(root, height=2, width=10)
textBox.pack()

def helloCallBack():
   print ("Below is the output from the shell script in terminal")
   subprocess.call(['./date.sh inputValue']) #shell=True)


buttonCommit=Button(root, height=1, width=10, text="Commit", 
                    command= helloCallBack) # retrieve_input())
#command=lambda: retrieve_input() >>> just means do this when i press the button
buttonCommit.pack()

mainloop()

0 个答案:

没有答案
相关问题