[Tutor] Tkinter grid manager question
Peter Otten
__peter__ at web.de
Sun Nov 27 10:19:38 CET 2011
Chris Hare wrote:
> I am attempting to create a form for the user to complete. I have the
> basic layout and supporting code working, but I am having a problem with
> getting things to display in the grid the way I want them.
>
> self.label1 = Label(self.frame, text = "Double
> click on a name from the list in the right. Make
> your changes in the field below and press the Save
> button.", fg="Blue", bg=backColor) self.label2 =
> Label(self.frame, text = "Current Animal Types",
> fg="Blue", bg=backColor)
> …...
> self.label1.grid(row=1, column=0,columnspan=3, sticky=W)
> self.label2.grid(row=2, column=0,columnspan=1, sticky=W)
> self.list.grid(row=2, column=3, columnspan=2, sticky=W)
> self.label3.grid(row=3, column=0,columnspan=1, sticky=W)
>
> My problem is that the cell which contains the text for label2 is the same
> size as the text in label1. What I am trying to accomplish is to have the
> text in label1 span the entire window, instead of having a huge cell with
> all of the label1 text in it.
>
> Ideas?
Columns are indexed from 0 to n-1, the rightmost column in the code above is
3 for the list widget, so you have 4 columns already. Add another column for
the list widget's columnspan=2 and you end up with 5 columns in total.
Therefore
self.label1.grid(row=1, column=0, columnspan=5, sticky=W)
should accomplish the desired layout.
More information about the Tutor
mailing list