Home > Back-end >  How do I display Text in a Tk Window
How do I display Text in a Tk Window

Time:12-25

I'm trying to post the text from a .txt file in text screen on a Tk window, but every time I click on the the file to display I get an error that says FileNotFoundError: [Errno 2] No such file or directory: 'dffffff.txt' How do I fix this error?

Here is what I tried.

v_entry = tkinter.Tk(className=' View Entrys' )
        v_entry.geometry("400x200")
        dir_path = (r'C:/Users/crist/OneDrive/Desktop/Express Main/Express Entrys/')
        vlist = os.listdir(dir_path)
        lbox = tkinter.Listbox(v_entry)
        lbox.place(x=268, y=1)
        for item in vlist:
            lbox.insert(tkinter.END, item)
        def scont(event):
            x = lbox.curselection()[0]
            file = lbox.get(x)
            with open(file) as file:
                configfile.insert(INSERT, file.read())
            text.delete('1.0', tkinter.END)
            text.insert(tkinter.END, file)
        text = tkinter.Text(v_entry, bg='cyan')
        text.pack()
        lbox.bind("<<ListboxSelect>>", scont)
        v_entry.mainloop()

CodePudding user response:

FileNotFoundError: [Errno 2] No such file or directory: Means that you're trying to access a path/file which does not exist.

Simply creating the directory should remove the error. You can recursively create a directory in powershell using this command:

New-Item C:/Users/crist/OneDrive/Desktop/Express Main/Express Entrys/ -ItemType Directory

CodePudding user response:

Check the dffffff.txt file. FileNotFoundError: [Errno 2] No such file or directory show when the file is not at the path.

  • Related