From: Hidetoshi NAGAI Date: 2010-02-11T23:24:39+09:00 Subject: Re: Need Code to Create Directory Picking Dialog Box From: Albert Schlef Subject: Re: Need Code to Create Directory Picking Dialog Box Date: Thu, 11 Feb 2010 05:41:38 +0900 Message-ID: > Alex DeCaria wrote: > > I have a Ruby program and want to be able to pick a directory using a > > dialog box. Does anyone have a quick, easy piece of code that will > > And here's how to do it in Ruby/Tk: And, if you hate that the eventloop wastes CPU power, --------------------------------------------------------------- require 'tk' Tk.root.withdraw def choose_directory(keys = {}) th = Thread.new{Tk.mainloop} # start the eventloop begin dir = Tk.chooseDirectory(keys) # show dialog Tk.update # for safety ensure th.kill # stop the eventloop end dir end if __FILE__ == $0 dir = choose_directory(:initialdir => '/', :title => 'test test test') p dir p choose_directory(:initialdir => dir, :title => 'test TEST test') end --------------------------------------------------------------- -- Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)