Home > Mobile >  Ask for user input file and store it in gui
Ask for user input file and store it in gui

Time:03-21

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

CodePudding user response:

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.

CodePudding user response:

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

  • Related