D
David Bailey
After a whole day of frustrating "experimentation" with no good results,
I was ready to give up and ask this question:
How do I place two vertical sets of widgets (inside of a left and right
frame), two horizontal set of widgets (inside of a top and bottom frame)
and one set of rectanges in a square grid (inside of a middle center
canvas in a middle center frame) to control the location of my "sets"?
But then I got angry (both with myself and Ruby/Tk) and became
determined to figure it out without asking.
It took me hours and hours, but I fainally "nailed" it! The source of
my frustration was not realizing that the
x,:y) coordinates were
relative to the parent widgets' origin (in my example these are TkRoot
and TkFrames).
If you want to take a look (where I've use :background, :borderwidth and
:relief options to make the frames and canvas stand out), here is the
Ruby code:
require "tk"
root=TkRoot.new
title=>'Ruby/Tk Geometry, Frame, Canvas, ' + \
'and Widget Meanderings', :geometry=>'705x700')
packer1 = { :fill=>:none }
# Note: These (x,y) coordinates are relative to the parent widget's
# (TkRoot's or TkFrame's) origin
placer1 = { :x=>0, :y=>0 }; placer2 = { :x=>0, :y=>600 }
placer3 = { :x=>0, :y=>40 }; placer4 = { :x=>100, :y=>100 };
placer5 = { :x=>600, :y=>100 }; placer6 = { :x=>0, :y=>100 }
topFrame = TkFrame.new(root, :width=>705, :height=>100, \
:borderwidth=>5, :relief=>:groove, :background=>
ink).place(placer1)
topFrameButton1 = TkButton.new(topFrame, :text=>'TFButton 1').\
place(placer1)
middleLeftFrame = TkFrame.new(root, :width=>100, :height=>500, \
:borderwidth=>5, :relief=>:groove, :background=>:cyan).place(placer6)
middleLeftFrameButton1 = TkButton.new(middleLeftFrame, :text=>\
'MLFButton 1').place(placer1)
middleLeftFrameButton2 = TkButton.new(middleLeftFrame, :text=>\
'MLFButton 2').place(placer3)
middleCenterFrame = TkFrame.new(root, :width=>500, :height=>500, \
:borderwidth=>5, :relief=>:groove, :background=>:blue).place(placer4)
middleCenterCanvas = TkCanvas.new(middleCenterFrame, :width=>477, \
:height=>477, :borderwidth=>5, :relief=>:groove,
:background=>:yellow).\
pack(packer1)
middleCenterCanvasButton1 = TkButton.new(middleCenterCanvas, :text=>\
'MCCButton 1').place(placer1)
middleRightFrame = TkFrame.new(root, :width=>105, :height=>500, \
:borderwidth=>5, :relief=>:groove, :background=>:green).place(placer5)
middleRightFrameButton1 = TkButton.new(middleRightFrame, :text=>\
'MRFButton 1').place(placer1)
bottomFrame = TkFrame.new(root, :width=>705, :height=>100, \
:borderwidth=>5, :relief=>:groove,
:background=>
range).place(placer2)
bottomFrameButton1 = TkButton.new(bottomFrame, :text=>'BFButton 1').\
place(placer1)
ev_quit = TkVirtualEvent.new('Control-c', 'Control-q', 'q')
Tk.root.bind(ev_quit, proc{Tk.exit}).focus
Tk.mainloop
I was ready to give up and ask this question:
How do I place two vertical sets of widgets (inside of a left and right
frame), two horizontal set of widgets (inside of a top and bottom frame)
and one set of rectanges in a square grid (inside of a middle center
canvas in a middle center frame) to control the location of my "sets"?
But then I got angry (both with myself and Ruby/Tk) and became
determined to figure it out without asking.
It took me hours and hours, but I fainally "nailed" it! The source of
my frustration was not realizing that the
relative to the parent widgets' origin (in my example these are TkRoot
and TkFrames).
If you want to take a look (where I've use :background, :borderwidth and
:relief options to make the frames and canvas stand out), here is the
Ruby code:
require "tk"
root=TkRoot.new
'and Widget Meanderings', :geometry=>'705x700')
packer1 = { :fill=>:none }
# Note: These (x,y) coordinates are relative to the parent widget's
# (TkRoot's or TkFrame's) origin
placer1 = { :x=>0, :y=>0 }; placer2 = { :x=>0, :y=>600 }
placer3 = { :x=>0, :y=>40 }; placer4 = { :x=>100, :y=>100 };
placer5 = { :x=>600, :y=>100 }; placer6 = { :x=>0, :y=>100 }
topFrame = TkFrame.new(root, :width=>705, :height=>100, \
:borderwidth=>5, :relief=>:groove, :background=>
topFrameButton1 = TkButton.new(topFrame, :text=>'TFButton 1').\
place(placer1)
middleLeftFrame = TkFrame.new(root, :width=>100, :height=>500, \
:borderwidth=>5, :relief=>:groove, :background=>:cyan).place(placer6)
middleLeftFrameButton1 = TkButton.new(middleLeftFrame, :text=>\
'MLFButton 1').place(placer1)
middleLeftFrameButton2 = TkButton.new(middleLeftFrame, :text=>\
'MLFButton 2').place(placer3)
middleCenterFrame = TkFrame.new(root, :width=>500, :height=>500, \
:borderwidth=>5, :relief=>:groove, :background=>:blue).place(placer4)
middleCenterCanvas = TkCanvas.new(middleCenterFrame, :width=>477, \
:height=>477, :borderwidth=>5, :relief=>:groove,
:background=>:yellow).\
pack(packer1)
middleCenterCanvasButton1 = TkButton.new(middleCenterCanvas, :text=>\
'MCCButton 1').place(placer1)
middleRightFrame = TkFrame.new(root, :width=>105, :height=>500, \
:borderwidth=>5, :relief=>:groove, :background=>:green).place(placer5)
middleRightFrameButton1 = TkButton.new(middleRightFrame, :text=>\
'MRFButton 1').place(placer1)
bottomFrame = TkFrame.new(root, :width=>705, :height=>100, \
:borderwidth=>5, :relief=>:groove,
:background=>
bottomFrameButton1 = TkButton.new(bottomFrame, :text=>'BFButton 1').\
place(placer1)
ev_quit = TkVirtualEvent.new('Control-c', 'Control-q', 'q')
Tk.root.bind(ev_quit, proc{Tk.exit}).focus
Tk.mainloop