delete_column ( index ) def _len_ ( self ): return self. update_column ( index, value ) def _delitem_ ( self, index ): self. get ( index ) def _setitem_ ( self, index, value ): return self. update_column ( index, data ) def _getitem_ ( self, index ): return self. delete_column ( index ) def update ( self, index, data ): self. _multicolumn_listbox, index ) def delete ( self, index ): self. get_column ( index ) def get ( self, index ): return Column ( self. _multicolumn_listbox = multicolumn_listbox def data ( self, index ): return self. number_of_rows class List_Of_Columns ( object ): def _init_ ( self, multicolumn_listbox ): self. delete_row ( index ) def _len_ ( self ): return self. update_row ( index, value ) def _delitem_ ( self, index ): self. set_selection ( indices ) def _getitem_ ( self, index ): return self. deselect_row ( index ) def set_selection ( self, indices ): self. select_row ( index ) def deselect ( self, index ): self. update_row ( index, data ) def select ( self, index ): self. delete_row ( index ) def update ( self, index, data ): self. insert_row ( data, index ) def delete ( self, index ): self. _multicolumn_listbox, index ) def insert ( self, data, index = None ): self. row_data ( index ) def get ( self, index ): return Row ( self. number_of_rows class Multicolumn_Listbox ( object ): _style_index = 0 class List_Of_Rows ( object ): def _init_ ( self, multicolumn_listbox ): self. data ()) def _len_ ( self ): return self. _index, data ) def _str_ ( self ): return str ( self. _index ) def update ( self, data ): self. _index = index def data ( self ): return self. number_of_columns class Column ( object ): def _init_ ( self, table, index ): self. _index ) def _str_ ( self ): return str ( self. _index, data ) def select ( self ): self. You can find more details about the Treeview widget here.# Version: 2.3 # Author: Miguel Martinez Lopez # Uncomment the next line to see my email # print("Author's email: %s"%"61706c69636163696f6e616d656469646140676d61696c2e636f6d".decode("hex")) import platform try : from Tkinter import Frame, BOTH, N, E, S, W, CENTER, Entry, Canvas, Label from tkFont import Font, nametofont from ttk import Treeview, Scrollbar, Style except ImportError : from tkinter import Frame, BOTH, N, E, S, W, CENTER, Entry, Canvas, Label from tkinter.font import Font, nametofont from tkinter.ttk import Treeview, Scrollbar, Style # Python 3 compatibility try : basestring except NameError : basestring = str class Row ( object ): def _init_ ( self, table, index ): self. ShowScores = tk.Button(scores, text="Show scores", width=15, command=show).grid(row=4, column=0)ĬloseButton = tk.Button(scores, text="Close", width=15, command=exit).grid(row=4, column=1) ListBox = ttk.Treeview(scores, columns=cols, show='headings') Label = tk.Label(scores, text="High Scores", font=("Arial",30)).grid(row=0, columnspan=3) ListBox.insert("", "end", values=(i, name, score)) TempList =, ,, ]įor i, (name, score) in enumerate(tempList, start=1): The second argument is the position of the new item in the tree. The first argument is the item's parent, since you want a table, all items have the same parent, the root "". Then set the column labels with tree.heading(, text="Label")Īnd add rows with tree.insert("", "end", values=(,, )) ShowScores = Button(scores, text = "Show scores",width = 15, command = show).grid(row = 4, column = 0)ĬloseButton = Button(scores, text = "Close",width = 15, command = exit).grid(row = 4, column = 1)Ī ttk.Treeview without the tree part can be used to display a table: tree = ttk.Treeview(master, columns=('Position', 'Name', 'Score'), show='headings') Label = Label(scores, text="High Scores", font = ("Arial",30)).grid(row = 0, columnspan = 3) ListBox.insert(END, "Position | Name \t\t |Score\n") TempList.sort(key=lambda e: e, reverse=True) The code I have written is below: from tkinter import * Without importing Pandas / SQL etc is there a better way of displaying this data? I have written a program which takes data from a text file and displays it in a table style format.įormatted using the program: Position | Name |Score
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |