我希望有人能为我想做的项目指明正确的方向。我的意图很简单,拥有一个允许用户输入字符串的 GUI,该字符串填充到预先确定的命令行文本行中,运行命令行并返回命令行屏幕上打印的内容。我一直倾向于使用 Python 来完成此任务,但我仍然不确定能够完成第一部分的语法,其中用户将输入一个字符串,并且该字符串将贯穿命令行文本行。任何形式的输入将不胜感激!
最佳答案
这是一个使用 tkinter for python 的简单 GUI
try:
import tkinter as tk # python v3
except:
import Tkinter as tk # python v2
# This function is called when the submit button is clicked
def submit_callback(input_entry):
print("User entered : " + input_entry.get())
return None
####################### GUI ###########################
root = tk.Tk()
root.geometry('300x150') #Set window size
# Heading
heading = tk.Label(root, text="A simple GUI")
heading.place(x = 100, y = 0)
input_label = tk.Label(root, text="Enter some text")
input_label.place(x = 0, y = 50)
input_entry = tk.Entry(root)
input_entry.place(x = 100, y = 50)
submit_button = tk.Button(root, text = "Submit", command = lambda: submit_callback(input_entry))
submit_button.place(x = 200, y = 90)
root.mainloop()
#############################################################
关于python - 用于命令行输入/输出的 GUI 界面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49211172/