[Tutor] Tkinter layout question
Phil
phil_lor at bigpond.com
Sun Apr 23 04:51:50 EDT 2017
On Sun, 23 Apr 2017 09:52:16 +0200
Peter Otten <__peter__ at web.de> wrote:
> 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()
Thank you again Peter. Of course your changes worked but at the moment I'm not sure why.
if root = tk.Tk() then why isn't table_class.DisplayTable(root, the same as table_class.DisplayTable(tk.Tk(),. Obviously it isn't but I don't know why.
Also I found that root.mainloop() isn't necessary in that the result is the same with or without. Perhaps it serves some other purpose?
--
Regards,
Phil
More information about the Tutor
mailing list