[Tutor] Tkinter -- Is there a Gridwidget?

Michael P. Reilly arcege@shore.net
Sun, 16 Jan 2000 10:33:37 -0500 (EST)


> I am writing a program that connects to a Database (Postgresql).
> I want to represent the result in a Grid.
> Is there a Grid-widget somewhere available for use in Tkinter?
> Is it difficult to adabt the textwidget for using it as a Grid?

Not so much a grid "widget", more of a Grid placement manager, to be
used instead if Pack or Place.  Here is an example, adapted from
Fredrik Lundh's _Introduction to Tkinter_
<URL: http://www.pythonware.com/library/tkinter/introduction/index.htm>

Python 1.5.2 (#6, Apr 20 1999, 10:35:35)  [GCC 2.7.2.2] on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> from Tkinter import *
>>> f = Frame()
>>> Label(f, text="First:").grid(row=0, sticky=W)
>>> Label(f, text="Second:").grid(row=1, sticky=W)
>>> e1 = Entry(f)
>>> e2 = Entry(f)
>>> e1.grid(row=0, column=1)
>>> e2.grid(row=1, column=1)
>>> cb = Checkbutton(f, text="Hardcopy")
>>> cb.grid(row=2, columnspan=2, sticky=W)
>>> f.pack()
>>> f.mainloop()

Rows and columns start at zero.  Grid is usually the easiest placement
manager to use.  There are some restrictions with using different
managers in the widgets - if you need to mix then, create "invisible"
Frame widgets (no border, no relief) with the different management
styles, then pack each as needed.

As for adapting the textwidget, I guess it would depend on what you
want to do. Many a time, I feel the dynamic nature of the text widget
makes addressing very difficult, but still doable.  What I mean is, you
have only as many columns on a line as you have characters on that
like.  But if you are just dumping data to the widget, then it's
certainly easy to write out a formatted string to each line so the
columns line up (just remember that the Text widget needs the newline to
go to the next row/line - which has always annoyed me).

Have fun!
  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Engineer | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------