简体   繁体   中英

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. Once the user enters it, the file will be moved and be stored on my gui interface. This is by using 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.

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:

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! ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM