From: “Harry T.” [email protected]
Subject: Re: Looking for good reads on Ruby TK GUI programming
Date: Thu, 9 Mar 2006 23:12:58 +0900
Message-ID: 200603090912662.SM02816@htruax
I basically want to switch between one or more windows, each window takes up
the
whole screen, the user would enter/view data in each window, basic GUI
stuff.
First of all, you’ll have to clarify the design concept of your GUI.
Probably, it will be clarified in your mind.
Do you mean the concept is such like as the following?
require ‘tk’
def window_setup(top)
top.overrideredirect(true)
top.geometry(“#{top.winfo_screenwidth}x#{top.winfo_screenheight}+0+0”)
top.pack_propagate(false)
TkFrame.new(top, :borderwidth=>2,
:relief=>:ridge).pack(:expand=>:true)
end
Tk.root.lower # This is important. If all toplevel windows (not
iconified or
# withdrawn) are set overrideredirect flags, the
application
# may not be able to get keyboard focus. So, keep the root
# widget under administration of window-manager, but put
it
# lowest layer.
top0 = TkToplevel.new
top0_f = window_setup(top0)
top1 = TkToplevel.new
top1_f = window_setup(top1)
top2 = TkToplevel.new
top2_f = window_setup(top2)
Tk.update_idletasks
top0.raise
#-------------------------------------------------------------
v1 = TkVariable.new
v2 = TkVariable.new
#-------------------------------------------------------------
top2
TkLabel.new(top1_f, :text=>‘edit STR1’).pack
e1 = TkEntry.new(top1_f, :textvariable=>v1).pack(:side=>:left)
b1 = TkButton.new(top1_f, :text=>‘OK’,
:command=>proc{top0.raise}).pack(:side=>:left)
e1.bind(‘Return’, proc{b1.invoke})
#-------------------------------------------------------------
top2
TkLabel.new(top2_f, :text=>‘edit STR2’).pack
e2 = TkEntry.new(top2_f, :textvariable=>v2).pack(:side=>:left)
b2 = TkButton.new(top2_f, :text=>‘OK’,
:command=>proc{top0.raise}).pack(:side=>:left)
e2.bind(‘Return’, proc{b2.invoke})
#-------------------------------------------------------------
top0
TkFrame.new(top0_f){|f|
TkLabel.new(f, :text=>‘STR1:’).pack(:side=>:left)
l = TkLabel.new(f, :textvariable=>v1, :anchor=>:w,
:width=>25, :relief=>:sunken).pack(:side=>:left)
b = TkButton.new(f, :text=>‘edit’, :command=>proc{
top1.raise
e1.focus # or e1.focus(true) (if ‘force’ flag is
required)
}).pack(:side=>:left)
l.bind(‘ButtonPress-1’, proc{b.invoke})
}.pack
TkFrame.new(top0_f){|f|
TkLabel.new(f, :text=>‘STR2:’).pack(:side=>:left)
l = TkLabel.new(f, :textvariable=>v2, :anchor=>:w,
:width=>25, :relief=>:sunken).pack(:side=>:left)
b = TkButton.new(f, :text=>‘edit’, :command=>proc{
top2.raise
e2.focus # or e2.focus(true) (if ‘force’ flag is
required)
}).pack(:side=>:left)
l.bind(‘ButtonPress-1’, proc{b.invoke})
}.pack
TkButton.new(top0_f, :text=>‘QUIT’, :command=>proc{exit}).pack
#-------------------------------------------------------------
Tk.mainloop