From: Hidetoshi NAGAI Date: 2006-02-20T18:54:57+09:00 Subject: Re: Ruby TK GUI question From: "Harry Truax" Subject: Ruby TK GUI question Date: Sat, 18 Feb 2006 01:57:00 +0900 Message-ID: <200602171156918.SM03060@htruax> > I am writing a Ruby GUI TK application where the top-most portion of the > screen is a line of static menu buttons. I would like the remaining lower > portion of the screen to be dynamic - as an example, one of the top static > buttons is pressed, in response to that, another window appears in the > dynamic area where someone can press more buttons, someone presses on of > those, which then draws a data window, erasing the window which had the > buttons, then someone closes the data window which brings the user back to > the window which was drawn in response to the button press from the static > button in the top portion of the screen. Is the one which you want like as the following? ====< example >==================================================== require 'tk' root = Tk.root root.overrideredirect(true) root.bind('Visibility'){root.raise} # keep on top root.bind('Configure'){ root.geometry("#{root.winfo_screenwidth}x#{root.winfo_reqheight}+0+0") } def create_toplevel(btn) btn.state(:disabled) begin top = TkToplevel.new top.bind('Destroy'){btn.state(:normal)} top rescue => e top.destroy if top btn.state(:normal) fail e end end def msg_window(btn, msg) top = create_toplevel(btn) TkLabel.new(top, :text=>msg).pack(:padx=>10, :pady=>5) TkButton.new(top, :text=>'close', :command=>proc{top.destroy}).pack end f = TkFrame.new.pack(:side=>:left) TkLabel.new(f, :text=>' launcher window ').pack(:side=>:left) TkButton.new(f, :text=>'foo'){|b| command{msg_window(b, 'foo')} }.pack(:side=>:left) TkButton.new(f, :text=>'bar'){|b| command{msg_window(b, 'bar')} }.pack(:side=>:left) TkButton.new(f, :text=>'baz'){|b| command{msg_window(b, 'baz')} }.pack(:side=>:left) TkButton.new(:text=>'quit', :command=>proc{exit}).pack(:side=>:right) Tk.mainloop =================================================================== -- Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)