Laura Creighton
2015-08-23 13:52:59 UTC
oooh. Seems that there is an undocumented feature we can use!
Laura
------- Forwarded Message
Return-Path: <tkinter-discuss-bounces+lac=***@python.org>
Date: Sun, 23 Aug 2015 12:40:02 +0200
From: Michael Lange <***@web.de>
To: tkinter-***@python.org
Message-Id: <***@web.de>
In-Reply-To: <***@lenny>
References: <***@fido.openend.se>
Hi,
On Sat, 22 Aug 2015 21:04:24 +0100
to hide hidden elements and display even a button that allows to toggle
between hidden elements on/off, however we need to do a little tcl to get
to this. Since the feature is not documented anywhere it might also be a
good idea to wrap this into a try...except. See this little code snippet:
#############################################
from Tkinter import *
import tkFileDialog as tkfd
root = Tk()
try:
# call a dummy dialog with an impossible option to initialize the file
# dialog without really getting a dialog window; this will throw a
# TclError, so we need a try...except :
try:
root.tk.call('tk_getOpenFile', '-foobarbaz')
except TclError:
pass
# now set the magic variables accordingly
root.tk.call('set', '::tk::dialog::file::showHiddenBtn', '1')
root.tk.call('set', '::tk::dialog::file::showHiddenVar', '0')
except:
pass
# a simple callback for testing:
def openfile(event):
fname = tkfd.askopenfilename()
print(fname)
root.bind('<Control-o>', openfile)
root.mainloop()
#############################################
Best regards
Michael
_______________________________________________
Tkinter-discuss mailing list
Tkinter-***@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss
------- End of Forwarded Message
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Laura
------- Forwarded Message
Return-Path: <tkinter-discuss-bounces+lac=***@python.org>
Date: Sun, 23 Aug 2015 12:40:02 +0200
From: Michael Lange <***@web.de>
To: tkinter-***@python.org
Message-Id: <***@web.de>
In-Reply-To: <***@lenny>
References: <***@fido.openend.se>
Hi,
On Sat, 22 Aug 2015 21:04:24 +0100
Hi,
I've found this little gem in the Tk docs
https://www.tcl.tk/man/tcl8.4/TkCmd/getOpenFile.htm#M13
From what I see "file patterns" in the file dialog are not "regex
patterns" and do not support special characters. Only things that work
1) * - any extension
2) "" - files without extension
3) literal extension without wildcard chars
Unfortunately it looks like there is no simple way to filter out hidden
files.
actually the unix tk file dialog has an an (however undocumented) featureI've found this little gem in the Tk docs
https://www.tcl.tk/man/tcl8.4/TkCmd/getOpenFile.htm#M13
From what I see "file patterns" in the file dialog are not "regex
patterns" and do not support special characters. Only things that work
1) * - any extension
2) "" - files without extension
3) literal extension without wildcard chars
Unfortunately it looks like there is no simple way to filter out hidden
files.
to hide hidden elements and display even a button that allows to toggle
between hidden elements on/off, however we need to do a little tcl to get
to this. Since the feature is not documented anywhere it might also be a
good idea to wrap this into a try...except. See this little code snippet:
#############################################
from Tkinter import *
import tkFileDialog as tkfd
root = Tk()
try:
# call a dummy dialog with an impossible option to initialize the file
# dialog without really getting a dialog window; this will throw a
# TclError, so we need a try...except :
try:
root.tk.call('tk_getOpenFile', '-foobarbaz')
except TclError:
pass
# now set the magic variables accordingly
root.tk.call('set', '::tk::dialog::file::showHiddenBtn', '1')
root.tk.call('set', '::tk::dialog::file::showHiddenVar', '0')
except:
pass
# a simple callback for testing:
def openfile(event):
fname = tkfd.askopenfilename()
print(fname)
root.bind('<Control-o>', openfile)
root.mainloop()
#############################################
Best regards
Michael
_______________________________________________
Tkinter-discuss mailing list
Tkinter-***@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss
------- End of Forwarded Message
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor