【发布时间】:2021-03-16 09:58:34
【问题描述】:
我在 python 中有一个简单的 GUI。我想打印用户从函数外部输入的值。我制作的代码如下所示
def save_BasePath():
Base_Path_info = Base_Path.get()
#print(Base_Path_info)
file_basepath = open("basepath.txt", "w")
file_basepath.write(str(Base_Path_info))
file_basepath.close()
app = Tk()
app.geometry("500x500")
app.title("Python File Handling in Forms")
heading = Label(text="Input Print", fg="black", bg="yellow", width="500",
height="3", font="10")
heading.pack()
Base_Path_text = Label(text="Base_Path :")
Base_Path_text.place(x=155, y=70)
Base_Path = StringVar()
Base_Path_entry = Entry(textvariable=Base_Path, width="30")
Base_Path_entry.place(x=155, y=100)
button_basepath = Button(app, text="Enter Base Path", command=save_BasePath, width="15", height="2", bg="grey")
button_basepath.place(x=175, y=125)
#I need the user input from the function here so that I can use it further
mainloop()
在按下按钮时,我得到了用户输入。我可以从 save_basepath 函数中打印。但我想从外部访问用户输入,以便我可以处理它。任何帮助表示赞赏
【问题讨论】:
-
您可以使用
Base_Path.get()从任何函数访问用户输入,那么您的问题到底是什么?
标签: python tkinter tkinter-entry