首页 > 解决方案 > 如何传递参数以从 tkinter 调用 shell 脚本?

问题描述

我想使用来自 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()

标签: python-3.xtkintersubprocess

解决方案


推荐阅读