zProblem

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Apr 14 02:38:38 EDT 2009


En Mon, 13 Apr 2009 15:13:53 -0300, norseman <norseman at hughes.net>  
escribió:
> Gabriel Genellina wrote:

>>  Now, if ... summarizes your problem, I think you should use the  
>> "place" geometry manager, not grid (nor pack).
>> The Tkinter documentation [1] is rather short but the Tcl docs [2] have  
>> more info.
>>  [1] http://effbot.org/tkinterbook/place.htm
>> [2] http://www.tcl.tk/man/tcl8.4/TkCmd/place.htm
>
> Thanks for the links but I'm having the same problems as before. [...]
> I can't visualize that working properly in my current need.  The mockup  
> board is to be size inflexible and real estate jammed with specifically  
> sized replaceable sections.  The question is how to make it happen.

Below there is an attempt to reproduce the layout you describe in the PDF:

 from Tkinter import *
root = Tk()
pane = Frame(root, width=400, height=300)
pane.pack(fill="both", expand=1)
w1 = Label(pane, text="1", bg="white")
w1.place(relwidth=0.1, relheight=0.5)
w2 = Label(pane, text="2", bg="yellow")
w2.place(relwidth=0.25, relheight=0.3, relx=0.1)
w3 = Label(pane, text="3", bg="red")
w3.place(relwidth=0.2, relheight=0.2, relx=0.1, rely=0.3)
w4 = Label(pane, text="4", bg="cyan")
w4.place(relwidth=0.05, relheight=0.2, relx=0.3, rely=0.3)
w5 = Label(pane, text="5", bg="blue")
w5.place(relwidth=0.35, relheight=0.5, rely=0.5)
w6 = Label(pane, text="X", bg="gray")
w6.place(relwidth=0.25, relheight=1, relx=0.35)
w7 = Label(pane, text='Rest of master control parceled as "whatever"',  
bg="white")
w7.place(relwidth=0.40, relheight=1, relx=0.60)
root.mainloop()

The "place" geometry manager is the most powerful (least restricted) of  
all three standard managers; for each widget, you specify its size and  
position (in relative or absolute terms) without further restrictions.

In this case, the same thing could be done using pack (requiring a few  
auxiliary frames) -- but this is not always the case. Like cutting a  
rectangular piece of wood with a linear saw: you can only make straight  
cuts from one side to the oposite one; you can't stop in the middle. Those  
are the kind of layouts pack is able to build.

The grid manager has its own restrictions too, although it's easier to use  
when building dialog boxes or input forms.

So the place manager is the only one that can provide the flexibility you  
apparently require. At least if you want a non-rectangular shape as the  
"parcel" example in the PDF (or overlapping widgets of any kind).

> Back to your question.  Yes - there is a great need for dictionary  
> adherence.  Especially when language translations are probable.
> Also - The Military, the Engineering/Architectural, Building, Map Making  
>   and Graphic Arts and Printing communities have all been 'trained' to  
> the concept of grid. Not to mention Pilots and Navagators. The average  
> person and the Reality Companies all understand the concept of parcels.  
>   Grid points can be used without the need to fill the intervening. Take  
> a look at the starts at night. ALL parcels must have one or more parcels  
> between them if they are not contiguous. How else can one walk down the  
> street?

Cells in the grid geometry manager must be rectangular, all of them have  
four neighbourghs (except at the boundary), and adjacent grid cells must  
have the same dimension at its common side. Those are strong restrictions  
and I believe "parcel" is a more generic term than that (just from the  
dictionary definition -- I'm not a native English speaker).

The only mismatch with your dictionary definition of "grid" would be the  
"uniform" part -- and from this Wikipedia article [1] you can see there  
are rectangular grids in addition to square grids (and triangular, and  
hexagonal, and...) so it's not just the idea of a crazy Tk designer...

> Are there any other GUI's that run Python code unchanged on Linux and  
> Windows?

Sure. I like wxPython. The question "Which is the best GUI toolkit?"  
arises about once per month in this group, see past messages...

[1] http://en.wikipedia.org/wiki/Grid_(spatial_index)


-- 
Gabriel Genellina




More information about the Python-list mailing list