tktable/ table on GUI - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: tktable/ table on GUI (/thread-8476.html) |
tktable/ table on GUI - garikhgh0 - Feb-22-2018 Hi, I have a question. I came accross a code in the internet, which adds a table on the GUI. But I can not find any documentation on this. So, please give me a hint how to add a dynamic table on GUI. Thanks a lot import tkinter as tk import tktable def table_test(): #### DEFINES THE INTERFACE #### master = tk.Tk() master.geometry('500x200+250+200') master.title('Dogs') #### DEFINING THE TABLE #### tb = tktable.Table(master, state='disabled', width=50, titlerows=1, rows=5, cols=4, colwidth=20) columns = ['Breed','Price','Location','Age'] #### LIST OF LISTS DEFINING THE ROWS AND VALUES IN THOSE ROWS #### values = [['Doodle','1500','Chicago','1'], ['Pug','700','Kansas City','2'], ['Westie','1000','Lincoln','1'], ['Poodle','900','Atlanta','2']] #### SETS THE DOGS INTO THE TABLE #### #### VVVVVVVVVVVVVVVVVVVVVVVVVVV #### #DEFINING THE VAR TO USE AS DATA IN TABLE var = tktable.ArrayVar(master) row_count=0 col_count=0 #SETTING COLUMNS for col in columns: index = "%i,%i" % (row_count,col_count) var[index] = col col_count+=1 row_count=1 col_count=0 #SETTING DATA IN ROWS for row in values: for item in row: print(item) index = "%i,%i" % (row_count,col_count) ## PLACING THE VALUE IN THE INDEX CELL POSITION ## var[index] = item #### IGNORE THIS IF YOU WANT, JUST SETTING SOME CELL COLOR #### try: if int(item) > 999: tb.tag_cell('green',index) except: pass ############################################################### col_count+=1 col_count=0 row_count+=1 #### ABOVE CODE SETS THE DOG INTO THE TABLE #### ################################################ #### VARIABLE PARAMETER SET BELOW ON THE 'TB' USES THE DATA DEFINED ABOVE #### tb['variable'] = var tb.pack() #tb.tag_cell('green',index) tb.tag_configure('green', background='green') #### MAINLOOPING #### tk.mainloop() table_test() RE: tktable/ table on GUI - Larz60+ - Feb-22-2018 tktable is not part of tkinter. This must be a routine written by author. It should be in same repository as where this code came from. RE: tktable/ table on GUI - garikhgh0 - Feb-22-2018 Here is the docs. https://www.eso.org/projects/vlt/sw-dev/tcl8.3.3/tktable2.7/tkTable.html RE: tktable/ table on GUI - Larz60+ - Feb-22-2018 Again, this looks like it was written by the European Southern Observatory. It's not officially a part of tkinter I don't see tkinter mentioned in this document either, but I do see tk which is what tkinter is wrapped around. So I checked tkinter.ttk and: >>> from tkinter import ttk >>> help('ttk.tktable') No Python documentation found for 'ttk.tktable'. Use help() to get the interactive help utility. Use help(str) for help on the str class. >>>And: >>> help('tkinter.tktable') No Python documentation found for 'tkinter.tktable'. Use help() to get the interactive help utility. Use help(str) for help on the str class. >>>doesn't appear to be part of that either. There are ways to integrate raw tk into tkinter, I've never done it myself, but you might want to take a look at: https://docs.python.org/3/library/tkinter.html Looks like a good class though! So, now you have the docs, |