From uvizhe at yandex.ru Sat Aug 8 16:59:16 2015 From: uvizhe at yandex.ru (Alexander Uvizhev) Date: Sat, 08 Aug 2015 17:59:16 +0300 Subject: [Tkinter-discuss] Text widget incorrect 'displaylines' count Message-ID: <4821251439045956@web1g.yandex.ru> Hi, Recently I came across some strangeness in tkinter Text widget. I bind event to it and the first time I insert text into widget the callback is called and reports wrong 'displaylines' count. Here is the code: === $ cat test_text.py import tkinter def check(event): lines = event.widget.count('1.0', 'end', 'displaylines') print(lines) root = tkinter.Tk() master = tkinter.Frame(master=root) master.grid() text = tkinter.Text(master=master, height=1) text.bind('', check) text.grid() text.insert('1.0', "1234567890") # first time insert text.insert('1.0', "1234567890") # second text.unbind('') master.mainloop() === Output: $ python3 test_text.py (10,) Is it what's supposed to be or some sort of bug? -- Alexander Uvizhev uvizhe at yandex.ru From klappnase at web.de Sun Aug 9 01:19:11 2015 From: klappnase at web.de (Michael Lange) Date: Sun, 9 Aug 2015 01:19:11 +0200 Subject: [Tkinter-discuss] Text widget incorrect 'displaylines' count In-Reply-To: <4821251439045956@web1g.yandex.ru> References: <4821251439045956@web1g.yandex.ru> Message-ID: <20150809011911.5c13448849c6a5f582fd2c4e@web.de> Hi, On Sat, 08 Aug 2015 17:59:16 +0300 Alexander Uvizhev wrote: > > Hi, > Recently I came across some strangeness in tkinter Text widget. I bind > event to it and the first time I insert text into widget > the callback is called and reports wrong 'displaylines' count. Here is (...) > > Is it what's supposed to be or some sort of bug? I guess something like this happens: * the text widget is created, but initially, before it is actually drawn onto screen, has virtually a size of 1*1 px * because of this the inserted 10-character text string is wrappped into 10 lines * this is when the first event is triggered and so it in fact correctly reports 10 lines * subsequent calls to insert() do not trigger a event * the next >cConfigure> event is triggered when the window is actually drawn after mainloop() is called, however in your example then the binding was already removed I modified your example a little to illustrate what I mean, without the unbind(); you can see then that after the window is visible the reported lines are as expected: ############################### import tkinter def check(event): print(event.widget.winfo_width(), event.widget.winfo_height()) print(event.widget.count('1.0', 'end', 'displaylines')) print() root = tkinter.Tk() master = tkinter.Frame(master=root) master.pack(fill='both', expand=1) text = tkinter.Text(master=master) text.bind('', check) text.pack(fill='both', expand=1) text.insert('1.0', "1234567890") # first time insert text.insert('1.0', "1234567890") # second master.mainloop() ############################## Best regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. A star captain's most solemn oath is that he will give his life, even his entire crew, rather than violate the Prime Directive. -- Kirk, "The Omega Glory", stardate unknown From pawel at mosakowski.net Tue Aug 18 00:13:22 2015 From: pawel at mosakowski.net (Pawel Mosakowski) Date: Mon, 17 Aug 2015 23:13:22 +0100 Subject: [Tkinter-discuss] new ttk theme made with theme_create() doesn't inherit from parent Message-ID: <20150817231322.3f293064@lenny> Hi, When I create a new theme and set it to inherit from already existing one, the new theme comes up empty. It has no elements and buttons displayed with it show only label, no other layout components. I have no idea if it's normal behaviour or something is wrong with my setup. Maybe I'm just using it wrong. I'm running Python 3.4.3 with tk 8.6.4 on Arch Linux. =============================================== Test program =============================================== import tkinter as tk import tkinter.ttk as ttk style = ttk.Style() print('Available themes: ', style.theme_names()) print('\nSetting theme to default') style.theme_use('default') print('\nDisplaying theme "{0}" elements'.format(style.theme_use())) print(style.element_names()) print('\nCreating new theme') style.theme_create('new_theme', parent='default') print('\nAvailable themes: ', style.theme_names()) print('\nSetting theme to new_theme') style.theme_use('new_theme') print('\nDisplaying theme "{0}" elements'.format(style.theme_use())) print(style.element_names()) ================================================= Output ================================================= Available themes: ('clam', 'alt', 'default', 'classic') Setting theme to default Displaying theme "default" elements ('label', '', 'focus', 'treearea', 'separator', 'image', 'arrow', 'downarrow', 'Menubutton.indicator', 'Treeitem.row', 'vsash', 'text', 'sizegrip', 'indicator', 'Treeheading.cell', 'leftarrow', 'border', 'Radiobutton.indicator', 'hsash', 'vseparator', 'fill', 'thumb', 'background', 'uparrow', 'hseparator', 'trough', 'rightarrow', 'Treeitem.indicator', 'slider', 'field', 'pbar', 'Checkbutton.indicator', 'textarea', 'client', 'tab', 'padding') Creating new theme Available themes: ('new_theme', 'clam', 'alt', 'default', 'classic') Setting theme to new_theme Displaying theme "new_theme" elements () =================================================== Output end =================================================== Thanks in advance, Pawel Mosakowski From lac at openend.se Sat Aug 22 13:03:46 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 22 Aug 2015 13:03:46 +0200 Subject: [Tkinter-discuss] tkinter file dialog pattern matching Message-ID: <201508221103.t7MB3kdx010426@fido.openend.se> Somebody on the tutor mailing list wants to match "all files and direcories in this directory that do not start with a ." The filetypes option seems only to want patterns to match, not patterns to exclude. Is my pattern matching magic just off, or is there no way to exclude things in a tkFileDialog? puzzled, Laura From pawel at mosakowski.net Sat Aug 22 22:04:24 2015 From: pawel at mosakowski.net (Pawel Mosakowski) Date: Sat, 22 Aug 2015 21:04:24 +0100 Subject: [Tkinter-discuss] tkinter file dialog pattern matching In-Reply-To: <201508221103.t7MB3kdx010426@fido.openend.se> References: <201508221103.t7MB3kdx010426@fido.openend.se> Message-ID: <20150822210424.321b826f@lenny> 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 are: 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. Check out this answer https://mail.python.org/pipermail//tutor/2011-November/086483.html Regards, Pawel Mosakowski On Sat, 22 Aug 2015 13:03:46 +0200 Laura Creighton wrote: > Somebody on the tutor mailing list wants to match > "all files and direcories in this directory that do not start > with a ." > > The filetypes option seems only to want patterns to match, not > patterns to exclude. Is my pattern matching magic just off, or > is there no way to exclude things in a tkFileDialog? > > puzzled, > Laura > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > https://mail.python.org/mailman/listinfo/tkinter-discuss From lac at openend.se Sat Aug 22 22:17:11 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 22 Aug 2015 22:17:11 +0200 Subject: [Tkinter-discuss] tkinter file dialog pattern matching In-Reply-To: <20150822210424.321b826f@lenny> References: <201508221103.t7MB3kdx010426@fido.openend.se> <20150822210424.321b826f@lenny> Message-ID: <201508222017.t7MKHBac022500@fido.openend.se> In a message of Sat, 22 Aug 2015 21:04:24 +0100, Pawel Mosakowski writes: >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 >are: >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. >Check out this answer >https://mail.python.org/pipermail//tutor/2011-November/086483.html > >Regards, >Pawel Mosakowski Thank you. Looks like it will be necessary to construct a new widget. I'm surprised ... Laura From Cameron at phaseit.net Sun Aug 23 00:51:02 2015 From: Cameron at phaseit.net (Cameron Laird) Date: Sat, 22 Aug 2015 22:51:02 +0000 Subject: [Tkinter-discuss] tkinter file dialog pattern matching In-Reply-To: <201508222017.t7MKHBac022500@fido.openend.se> References: <201508221103.t7MB3kdx010426@fido.openend.se> <20150822210424.321b826f@lenny> <201508222017.t7MKHBac022500@fido.openend.se> Message-ID: <20150822225102.GA12242@lairds.us> On Sat, Aug 22, 2015 at 10:17:11PM +0200, Laura Creighton wrote: > In a message of Sat, 22 Aug 2015 21:04:24 +0100, Pawel Mosakowski writes: > >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 > >are: > >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. > >Check out this answer > >https://mail.python.org/pipermail//tutor/2011-November/086483.html > > > >Regards, > >Pawel Mosakowski > > Thank you. Looks like it will be necessary to construct a new > widget. I'm surprised ... . . . More than I. I can understand your disappointment that file-dialogue "file patterns" have such a rudimentary syntax; I speculate with considerable confidence that the authors acted with sh as the model most in their mind. You're quite right, Laura, that the elements are at hand to allow you to construct your own variant. If the history of getOpenFile truly interests you, act quickly: while we can get to the authors now, it won't be many cycles more before their memories and records senesce irretrievably. From klappnase at web.de Sun Aug 23 12:40:02 2015 From: klappnase at web.de (Michael Lange) Date: Sun, 23 Aug 2015 12:40:02 +0200 Subject: [Tkinter-discuss] tkinter file dialog pattern matching In-Reply-To: <20150822210424.321b826f@lenny> References: <201508221103.t7MB3kdx010426@fido.openend.se> <20150822210424.321b826f@lenny> Message-ID: <20150823124002.7391f37e21f9b5cfaa91770f@web.de> Hi, On Sat, 22 Aug 2015 21:04:24 +0100 Pawel Mosakowski wrote: > 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 > are: > 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) feature 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('', openfile) root.mainloop() ############################################# Best regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. This cultural mystique surrounding the biological function -- you realize humans are overly preoccupied with the subject. -- Kelinda the Kelvan, "By Any Other Name", stardate 4658.9 From klappnase at web.de Sun Aug 23 13:11:00 2015 From: klappnase at web.de (Michael Lange) Date: Sun, 23 Aug 2015 13:11:00 +0200 Subject: [Tkinter-discuss] tkinter file dialog pattern matching In-Reply-To: <201508222017.t7MKHBac022500@fido.openend.se> References: <201508221103.t7MB3kdx010426@fido.openend.se> <20150822210424.321b826f@lenny> <201508222017.t7MKHBac022500@fido.openend.se> Message-ID: <20150823131100.39d726533290e9d307e0a31e@web.de> Hi, On Sat, 22 Aug 2015 22:17:11 +0200 Laura Creighton wrote: > In a message of Sat, 22 Aug 2015 21:04:24 +0100, Pawel Mosakowski > writes: > >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 > >are: > >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. if you only need to hide hidden files, please see my other post. If you need a more versatile file dialog widget, you might want to consider wrapping an existing tcl widget for tkinter, this is usually rather easy once you understand how it is done (all you need is mostly the man page and a little time) and might save you a lot of headaches. One example that might be interisting is here: http://chiselapp.com/user/schelte/repository/fsdialog/index You might also want to try the Tix.ExFileSelectDialog, it is rather dated, but actually has a switch to toggle hidden files on/off and wildcard filtering capabilities. Unfortunately here with debian jessie I can only test it with Tcl, with python for some reason I get a segfault :-( Best regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. I realize that command does have its fascination, even under circumstances such as these, but I neither enjoy the idea of command nor am I frightened of it. It simply exists, and I will do whatever logically needs to be done. -- Spock, "The Galileo Seven", stardate 2812.7 From lac at openend.se Sun Aug 23 15:52:59 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 23 Aug 2015 15:52:59 +0200 Subject: [Tkinter-discuss] tkinter file dialog pattern matching (fwd) Message-ID: <201508231352.t7NDqxVk005849@fido.openend.se> oooh. Seems that there is an undocumented feature we can use! Laura ------- Forwarded Message Return-Path: Date: Sun, 23 Aug 2015 12:40:02 +0200 From: Michael Lange To: tkinter-discuss at python.org Message-Id: <20150823124002.7391f37e21f9b5cfaa91770f at web.de> In-Reply-To: <20150822210424.321b826f at lenny> References: <201508221103.t7MB3kdx010426 at fido.openend.se> Hi, On Sat, 22 Aug 2015 21:04:24 +0100 Pawel Mosakowski wrote: > 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 > are: > 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) feature 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('', openfile) root.mainloop() ############################################# Best regards Michael _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org https://mail.python.org/mailman/listinfo/tkinter-discuss ------- End of Forwarded Message From lac at openend.se Sun Aug 23 15:54:32 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 23 Aug 2015 15:54:32 +0200 Subject: [Tkinter-discuss] tkinter file dialog pattern matching In-Reply-To: <20150823124002.7391f37e21f9b5cfaa91770f@web.de> References: <201508221103.t7MB3kdx010426@fido.openend.se> <20150822210424.321b826f@lenny> <20150823124002.7391f37e21f9b5cfaa91770f@web.de> Message-ID: <201508231354.t7NDsWBF006200@fido.openend.se> Thank you very much. :) Laura From daniel.graham at duke.edu Sun Aug 23 15:11:03 2015 From: daniel.graham at duke.edu (Daniel Graham, Ph.D.) Date: Sun, 23 Aug 2015 13:11:03 +0000 Subject: [Tkinter-discuss] Tkinter-discuss Digest, Vol 136, Issue 3 In-Reply-To: References: Message-ID: <3F067C7B-F3EE-47C3-B280-446B68E9E38C@duke.edu> I use fnmatch: for path, dirs, files in os.walk(root): # exclude dirs dirs[:] = [os.path.join(path, d) for d in dirs if not fnmatch.fnmatch(d, exclude)] # exclude files files = [os.path.join(path, f) for f in files if not fnmatch.fnmatch(f, exclude)] where exclude=r?.*? -Dan On Aug 23, 2015, at 6:00 AM, tkinter-discuss-request at python.org wrote: Send Tkinter-discuss mailing list submissions to tkinter-discuss at python.org To subscribe or unsubscribe via the World Wide Web, visit https://mail.python.org/mailman/listinfo/tkinter-discuss or, via email, send a message with subject or body 'help' to tkinter-discuss-request at python.org You can reach the person managing the list at tkinter-discuss-owner at python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Tkinter-discuss digest..." Today's Topics: 1. tkinter file dialog pattern matching (Laura Creighton) 2. Re: tkinter file dialog pattern matching (Pawel Mosakowski) 3. Re: tkinter file dialog pattern matching (Laura Creighton) 4. Re: tkinter file dialog pattern matching (Cameron Laird) ---------------------------------------------------------------------- Message: 1 Date: Sat, 22 Aug 2015 13:03:46 +0200 From: Laura Creighton To: tkinter-discuss at python.org Subject: [Tkinter-discuss] tkinter file dialog pattern matching Message-ID: <201508221103.t7MB3kdx010426 at fido.openend.se> Content-Type: text/plain; charset="us-ascii" Somebody on the tutor mailing list wants to match "all files and direcories in this directory that do not start with a ." The filetypes option seems only to want patterns to match, not patterns to exclude. Is my pattern matching magic just off, or is there no way to exclude things in a tkFileDialog? puzzled, Laura ------------------------------ Message: 2 Date: Sat, 22 Aug 2015 21:04:24 +0100 From: Pawel Mosakowski To: tkinter-discuss at python.org Subject: Re: [Tkinter-discuss] tkinter file dialog pattern matching Message-ID: <20150822210424.321b826f at lenny> Content-Type: text/plain; charset=US-ASCII 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 are: 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. Check out this answer https://mail.python.org/pipermail//tutor/2011-November/086483.html Regards, Pawel Mosakowski On Sat, 22 Aug 2015 13:03:46 +0200 Laura Creighton wrote: Somebody on the tutor mailing list wants to match "all files and direcories in this directory that do not start with a ." The filetypes option seems only to want patterns to match, not patterns to exclude. Is my pattern matching magic just off, or is there no way to exclude things in a tkFileDialog? puzzled, Laura _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org https://mail.python.org/mailman/listinfo/tkinter-discuss ------------------------------ Message: 3 Date: Sat, 22 Aug 2015 22:17:11 +0200 From: Laura Creighton To: Pawel Mosakowski Cc: tkinter-discuss at python.org, lac at openend.se Subject: Re: [Tkinter-discuss] tkinter file dialog pattern matching Message-ID: <201508222017.t7MKHBac022500 at fido.openend.se> Content-Type: text/plain; charset="us-ascii" In a message of Sat, 22 Aug 2015 21:04:24 +0100, Pawel Mosakowski writes: 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 are: 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. Check out this answer https://mail.python.org/pipermail//tutor/2011-November/086483.html Regards, Pawel Mosakowski Thank you. Looks like it will be necessary to construct a new widget. I'm surprised ... Laura ------------------------------ Message: 4 Date: Sat, 22 Aug 2015 22:51:02 +0000 From: Cameron Laird To: Laura Creighton Cc: tkinter-discuss at python.org Subject: Re: [Tkinter-discuss] tkinter file dialog pattern matching Message-ID: <20150822225102.GA12242 at lairds.us> Content-Type: text/plain; charset=us-ascii On Sat, Aug 22, 2015 at 10:17:11PM +0200, Laura Creighton wrote: In a message of Sat, 22 Aug 2015 21:04:24 +0100, Pawel Mosakowski writes: 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 are: 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. Check out this answer https://mail.python.org/pipermail//tutor/2011-November/086483.html Regards, Pawel Mosakowski Thank you. Looks like it will be necessary to construct a new widget. I'm surprised ... . . . More than I. I can understand your disappointment that file-dialogue "file patterns" have such a rudimentary syntax; I speculate with considerable confidence that the authors acted with sh as the model most in their mind. You're quite right, Laura, that the elements are at hand to allow you to construct your own variant. If the history of getOpenFile truly interests you, act quickly: while we can get to the authors now, it won't be many cycles more before their memories and records senesce irretrievably. ------------------------------ Subject: Digest Footer _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org https://mail.python.org/mailman/listinfo/tkinter-discuss ------------------------------ End of Tkinter-discuss Digest, Vol 136, Issue 3 *********************************************** -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris_roysmith at internode.on.net Mon Aug 24 02:43:19 2015 From: chris_roysmith at internode.on.net (Chris Roy-Smith) Date: Mon, 24 Aug 2015 10:43:19 +1000 Subject: [Tkinter-discuss] tkinter file dialog pattern matching (fwd) In-Reply-To: <201508231352.t7NDqxVk005849@fido.openend.se> References: <201508231352.t7NDqxVk005849@fido.openend.se> Message-ID: <55DA68A7.2060004@internode.on.net> On 23/08/15 23:52, Laura Creighton wrote: > oooh. Seems that there is an undocumented feature we can use! > > Laura > > ------- Forwarded Message > > Return-Path: > Date: Sun, 23 Aug 2015 12:40:02 +0200 > From: Michael Lange > To: tkinter-discuss at python.org > Message-Id: <20150823124002.7391f37e21f9b5cfaa91770f at web.de> > In-Reply-To: <20150822210424.321b826f at lenny> > References: <201508221103.t7MB3kdx010426 at fido.openend.se> > > Hi, > > On Sat, 22 Aug 2015 21:04:24 +0100 > Pawel Mosakowski wrote: > >> 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 >> are: >> 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) feature > 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('', openfile) > > root.mainloop() > ############################################# > > Best regards > > Michael > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > https://mail.python.org/mailman/listinfo/tkinter-discuss > > ------- End of Forwarded Message > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > Thanks Laura, That does exactly what I wanted to do.