Once an item is selected, we can perform certain operations to delete or edit the item. The Treeview widget items can be edited and deleted by selecting the item using lection() function. If we want to create a Treeview widget, then we can use Treeview(parent, columns) constructor to build the table. Each directory contains files or additional directories. In this structure, each row can represent a file or a directory. I use the variable widths to define the columns widths at initialisation of the tree and these remain fixed after refresh.Tkinter Treeview widget is used to display the data in a hierarchical structure. Where I can force the column "key" to stay hidden by instructing which columns I want to display by using the option: ee = ('name', 'value') ("#0", width=widths, minwidth=widths) # tree column Perhaps worth mentioning that I also have a hidden column which gets displayed after the automatic adjustment of the columns: widths = (200, 300, 300) Which works fine, but hides the tree column or you can use also the following combination, if you want both the column #0 and the headings to display: ee = column #0), in which case you want to use the option: ee = 'tree' In my case, I also have a tree column (i.e. I defined the ee option to keep the columns widths fixed after refreshing the tree. I had the same issue of the tree resizing while refreshing the data.įor me, a variation of the answer by user16129445 (see above) worked perfectly. eeview_sort_column(self.table_tree, _col, True))ĭue to my reputation points, I cannot post a simple comment. Self.table_tree.heading(i, text=i, command= lambda _col=i: \ Self.table_lumn(i, width=h_col_w, stretch=True) "set the width of the column to the width of the column name" Wcols.append(self.table_lumn(i, width=None))Īnd then later on self.table_tree=column_names columns = įor each in self.table_tree.get_children():Ĭolumns = list(self.table_em(each, option='values')) Finally fixed it by just saving the width of the columns in a list before clearing the treeview, and then using those width to compare with new ones and using the larger. Had the same issue myself, after trying everything like root.update(), treeview.update() and stroy() which messed up all my gui. **(col, width= int(600 / len(col_name)), minwidth=0, anchor='center',stretch=0) # auto adjust column width** Self.tbTitlelabel = table_item.db_nameĬol_name = table_l_name Print( self.table_index, self.table_list) If len(self.table_list) > self.table_index: **# if call the function during the page intial, the table width is good.** Ysb = ttk.Scrollbar(self, orient='vertical', command=) ee = ttk.Treeview(self, height=10, show = 'headings', selectmode='browse') nfigure("Treeview.Heading", font=("Verdana", 15)) Self.preLabel = tk.Button(self, text="Previous", font=("Verdana", 18, "bold"), bg='#C6E2FF', fg='darkblue', command=lambda:self.showTable() ) **# if call the function by the button, the table width change.** Self.nextLabel = tk.Button(self, text="Next", font=("Verdana", 8, "bold"), bg='#C6E2FF', fg='darkblue',command=lambda:self.nextTable()) Self.tbTitlelabel = tk.Button(self, text="Table", font=("Verdana", 18, "bold"), bg='#C6E2FF', fg='darkblue', command=lambda: controller.show_frame(start_page.StartPage)) Table_list = sample.scan_result.table_list Thanks a lot ! my code is attached at the bottom. and I found it change with the number of column, as shown below. However, if I click a button to call the same function to insert the same data row, then the treeview table width will change. When the code was run the first time, the column width was adjusted by the width normally and the total table width is well fit and correct, as shown below. the function is called when showing the page(I put comment for the line when its called). I wrote the python3 code in Pycharm 2018.3-community, and used a function(show table) to insert the data rows and used "lumn(col, width = int( total_width / len(cols)), minwidth=0, anchor='center',stretch=0 )" to set the column width. Since the number of column in different tables may not be the same, I want to auto adjust the width of column so that the total width of the treeview table is fixed. The heading is the table schema, and insert data row to the treeview table. I am trying to use python tkinter to build a interface to show database table information with Treeview.
0 Comments
Leave a Reply. |