Phil wrote:

> On Thu, 20 Apr 2017 13:43:07 +0100
> Alan Gauld via Tutor <tutor@python.org> wrote:
> 
>> If still confused drop a question here.
> 
> I hope I'm not over doing the questions here. I'm only posting after hours
> of experimenting and Internet searching.
> 
> How do I create multiple instances of the table on the one frame? I think
> the table class as presented is not capable of that. If I create multiple
> instances like this then, of course, I end up with two instances of the
> same frame.
> 
> import tkinter as tk
> import table_class
> 
> tab = table_class.DisplayTable(tk.Tk(),
>                     ["Left","middle","Right"],
>                     [[1,2,1],
>                     [3,4,3],
>                     [5,6,5]],
>                     datacolor='blue',
>                     cellcolor='yellow',
>                     gridcolor='red',
>                     hdcolor='black')
> 
> 
> second_tab = table_class.DisplayTable(tk.Tk(),
>                     ["Left","middle","Right"],
>                     [[1,2,1],
>                     [3,4,3],
>                     [5,6,5]],
>                     datacolor='blue',
>                     cellcolor='green',
>                     gridcolor='red',
>                     hdcolor='black')
> 
> second_tab.pack(side = tk.LEFT)
> tab.pack()
> 
> I've tried different pack options including packing onto the parent frame.
> 

If you wrote the above with Buttons instead of DisplayTables you'd encounter 
the same behaviour. The problem is that you call tkinter.Tk() twice (which 
is generally a recipe for disaster; if you want multiple windows use 
tkinter.Toplevel() for all but the first one). 

Once you have fixed that you should be OK:

import tkinter as tk
import table_class

root = tk.Tk()

tab = table_class.DisplayTable(root,
                    ["Left","middle","Right"],
                    [[1,2,1],
                    [3,4,3],
                    [5,6,5]],
                    datacolor='blue',
                    cellcolor='yellow',
                    gridcolor='red',
                    hdcolor='black')

second_tab = table_class.DisplayTable(root,
                    ["Left","middle","Right"],
                    [[1,2,1],
                    [3,4,3],
                    [5,6,5]],
                    datacolor='blue',
                    cellcolor='green',
                    gridcolor='red',
                    hdcolor='black')

tab.pack(side=tk.LEFT)
second_tab.pack()

root.mainloop()




_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to