[英]Ask for user input file and store it in gui
I want to do a project.我想做一个项目。 For it, the gui asks for a file path and file name.
为此,gui 要求提供文件路径和文件名。 Once the user enters it, the file will be moved and be stored on my gui interface.
用户输入后,文件将被移动并存储在我的 gui 界面上。 This is by using python
这是通过使用 python
What are you really attempting to do?你到底想做什么? I do not understand your idea.
我不明白你的想法。 Do you mean to get a file and display the contents?
你的意思是获取一个文件并显示内容? If so, the tkinter filedialog module.
如果是这样,tkinter filedialog 模块。
from tkinter import filedialog as fidia
filename = fidia.askopenfilename()
fileread = os.open(filename, "rt")
print(os.fileread())
As I said, I am not sure about your question.正如我所说,我不确定你的问题。
Assuming you're using Tkinter as GUI module, you should import the library "filedialog" to do something like this:假设您使用 Tkinter 作为 GUI 模块,您应该导入库“filedialog”来执行如下操作:
from tkinter import *
from tkinter import filedialog
class Window: # Your main window's class
def __init__(root): # window's constructor method
root.win = Tk() # the declaration of the Tkinter object
filename = filedialog.askopenfilename(root.win) # The variable holding the string of the file opened in the dialog
root.win.mainloop() # Calling the tkinter method that starts the window
myWin = Window()
By the way: I think your question is legit, but you should try to find out more about this on the official docs顺便说一句:我认为你的问题是合法的,但你应该尝试在官方文档上找到更多相关信息
Next time take some time to read the docs, you would have found the answer in 10 minutes, just be patient!下次花些时间阅读文档,您将在 10 分钟内找到答案,耐心等待! ;)
;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.