[Tutor] Tables in Tkinter

Alan Gauld alan.gauld at yahoo.co.uk
Fri Mar 3 20:47:35 EST 2017


On 03/03/17 21:15, Pooja Bhalode wrote:
> Hi Alan,
> 
> Can you please guide me to an example related to this problem? I do not
> know how to use the scrollable frame, set backgrounds etc.
> Sorry, I am new to tables in Tkinter. I could not find any examples as well

WE are all new to tables in Tkinter because they don;t exist.
You either have to build your own or find a third party one.

Here is a very simple 3 row, 2 column table:

>>> top = tk.Tk()
>>> tab = tk.Frame(top)
>>> tk.Label(tab, text="Left", border=2, relief=tk.SUNKEN,
width=5).grid(column=0,row=0)
>>> tk.Label(tab, text="Right", border=2, relief=tk.SUNKEN,
width=5).grid(column=1,row=0)
>>> tk.Label(tab, text="1L", border=2, relief=tk.SUNKEN,
width=5).grid(column=0,row=1)
>>> tk.Label(tab, text="2L", border=2, relief=tk.SUNKEN,
width=5).grid(column=0,row=2)
>>> tk.Label(tab, text="1R", border=2, relief=tk.SUNKEN,
width=5).grid(column=1,row=1)
>>> tk.Label(tab, text="2R", border=2, relief=tk.SUNKEN,
width=5).grid(column=1,row=2)
>>> tab.pack()
>>> top.mainloop()

I don't have PMW installed but if you substitute

tab = pmw.ScrolledFrame(top)

for the Frame in my example it might just work!

Alternatively there is a ScrolledWindow in Tix,
although I've never used it. (Tix also has a Grid
and ScrolledGrid pair which I've tried to use
but failed to get it to work!)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list