简体   繁体   English

询问用户输入文件并将其存储在 gui 中

[英]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.

相关问题 我如何要求用户输入数字然后存储在文本文件中? - How do I ask user to input numbers to then store in text file? 当 tkinter gui 在全屏模式下运行时总是要求用户输入 - Always ask for user input while tkinter gui is running in fullscreen mode 使用pandas时如何要求用户输入文件的文件路径? - How to ask user to input a filepath for a file while using pandas? 如何存储元组并继续要求用户输入更多值,直到用户输入“完成”? - How to store tuples and continue to ask the user to input more values until user inputs 'done'? 如何将用户GUI条目存储在另一个py文件中 - How to store user GUI entry in another py file 如何让一个 python 文件要求用户输入,然后将此输入传递给第二个 .py 文件? - How can I make one python file ask for user input and then pass this input to a second .py file? 将用户输入值存储在文件中以供另一个脚本使用 - Store User Input Values in File for Another Script Python:如何将用户文本输入存储在文件中? - Python: How to store user text input in a file? 如何将用户输入存储到 json 文件? - How to store user input to a json file? 在 Tkinter 中打开.py 文件并通过 GUI 提供用户输入 - Open .py file in Tkinter and supply user input through GUI
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM