How do you do this in python with tk?

Jeff Epler jepler at unpythonic.net
Fri Oct 8 01:44:13 CEST 2004


You could create a Text widget and insert lines of text in it.

import Tkinter
def add_rows(w, titles, rows):
    for r in rows:
        for t, v in zip(titles, r):
            w.insert("end", "%s:\t%s\n" % (t, v))
        w.insert("end", "\n")

app = Tkinter.Tk()
t = Tkinter.Text(app)
t.pack()
info = [['Ali',18],
        ['Zainab',16],
        ['Khalid',18]]
add_rows(t, ["Name", "Age"], info)
app.mainloop()

If there are many lines, you can use a scrollbar widget to scroll the
text widget.  You can use the tabs= argument of the Text widget to
adjust the alignment of the second column.  If you want to make the
items "interactive", you can use tags and tag_bind to react to things
like button presses.  You can set the text widget to be "disabled" to
keep the user from changing the contents.

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20041007/213a86b9/attachment.pgp>


More information about the Python-list mailing list