Python Forum
[Tkinter] Exclude hidden file, filedialog.askopenfile
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Exclude hidden file, filedialog.askopenfile
#1
I started learning Python very recently. It seems to well thought out.

In tkinter I have setup the filedialog to open the home directory on my Linux system so I can select a file. I am getting all the hidden files (.filename) in the file chooser window.

How can I exclude the hidden file (and directories)?

W.
Reply
#2
After a some research I found a resolve that should work for you.
The showHiddenVar is used to select if the hidden files will be displayed by default or not. If you don't want to allow the users to toggle between displaying and hiding the hidden files, then simply set showHiddenBtn to '0'.

from tkinter import *
from tkinter import filedialog

root = Tk()

try:
    try:
        root.tk.call('tk_getOpenFile', '-foobarbaz')
    except TclError:
        pass

    root.tk.call('set', '::tk::dialog::file::showHiddenBtn', '1')
    root.tk.call('set', '::tk::dialog::file::showHiddenVar', '0')
except:
    pass

def openfile(event):
    fname = filedialog.askopenfilename(initialdir='/', title='Select file', filetypes=(('CSV files', '*.csv'), ('all files', '*.*')))
    print(fname)
root.bind('<Control-o>', openfile)

root.mainloop()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] filedialog, open a file error liketocode 4 3,352 Dec-07-2022, 10:51 PM
Last Post: liketocode
  [Tkinter] MenuBar hidden when new window opens john8888 5 1,431 Sep-14-2022, 02:32 PM
Last Post: john8888
  [PyQt] saving text file by FileDialog option atlass218 14 4,623 Feb-19-2020, 09:22 AM
Last Post: atlass218
  [Tkinter] Unable to save filepath to config.ini file using filedialog.askopenfilename JackMack118 10 4,957 Dec-29-2019, 08:12 PM
Last Post: JackMack118
  tkinter filedialog and pickle - custom icon question. kim07133 0 2,765 Jan-08-2018, 12:10 PM
Last Post: kim07133
  [Tkinter] filedialog. FULL SCREEN issac_n 0 3,133 Dec-05-2017, 07:33 AM
Last Post: issac_n

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020