python-3.x - 如何传递参数以从 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()
解决方案
推荐阅读
- mysql - 如何设置 Adodb.Parameter?MySQL 参数类型无效
- python - 同时使用两个程序从 CSV 读取
- javascript - 电子邮件和密码验证在 JavaScript 代码中不起作用
- python - Flask SQLAlchemy:如何获取最近的 5 行?
- java - 在 CPP jni 中存储对象/字符串
- git - Git Merge 错误地识别块中的冲突
- python - 当我没有任何分隔符时,有什么方法可以将 pandas 列中的单个字符串拆分为多列?
- roku - 如何在列表和网格节点禁用 FF/RW 键?
- reactjs - React-Hooks:如何创建可重用的数据表组件?
- javascript - 以角度8将文件列表转换为json格式