From: Osuka Adartse Date: 2003-12-21T05:08:57+09:00 Subject: Re: tk file dialog and directories Ara.T.Howard wrote: > On Sun, 21 Dec 2003, Hidetoshi NAGAI wrote: > > >>Date: Sun, 21 Dec 2003 00:35:37 +0900 >>From: Hidetoshi NAGAI >>Newsgroups: comp.lang.ruby >>Subject: Re: tk file dialog and directories >> >>Hi, >> >>From: "Ara.T.Howard" >>Subject: tk file dialog and directories >>Date: Sat, 20 Dec 2003 10:11:53 +0900 >>Message-ID: >> >>>anyone know how to make file dialogs allow the seletion of _directories_? >>>example code out there? >> >>If you use Tk8.3+, please use 'Tk.chooseDirectory' method. > > > > thanks! > > -a A lil' example I cooked someday, works in linux/windows(using tk8.4.4). the idea was select a dir with mp3's #!/usr/local/bin/ruby require 'tk' require 'tkscrollbox' Dir.chdir('/dev') bdir=TkVariable.new(value=Dir.getwd) mywin=TkRoot.new{title 'My Test ver 0.02'; resizable(1,1); minsize(640,480); maxsize(640,480); background '#DFEFF9'} flist=TkScrollbox.new(mywin){ relief 'groove' width 40 height 80 background '#FFFFEA' foreground '#0000AA' pack('side'=>'left')} TkButton.new(mywin){ # bitmap TkPhotoImage.new('file'=>['f:/dev/aIcon.GIF']) text 'Change Directory' command { bdir.value=Tk.chooseDirectory Dir.chdir(bdir.value) flist.delete 0,'end' flist.insert 0,*Dir['*.mp3'].sort! flist.activate(0) pack } pack } flist.insert 'end',*Dir['*.mp3'].sort! flist.focus flist.activate(0) flist.bind "Control-q", proc{exit} flist.bind "Double-Button-1", proc{print 'clicked: ',bdir.value,'/',TkSelection.get,"\n"} Tk.mainloop #print "\n",bdir.value