Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does tkinter have a table widget?

Tags:

python

tkinter

I'm learning Python, and I would like to use it to create a simple GUI application, and since Tkinter is already built-in (and very simple to use) I would like to use it to build my application.

I would like to make an app that will display a table that contains some data that I've loaded from my database.

I've searched for table but have not been able to find any examples and / or documentation regarding a Tkinter table component.

Does Tkinter have a built in table component? If not, what could I / should I use instead?

like image 411
Freewind Avatar asked Feb 19 '12 09:02

Freewind


People also ask

What widgets are available in Tkinter?

Ttk Widgets Ttk comes with 18 widgets, twelve of which already existed in tkinter: Button , Checkbutton , Entry , Frame , Label , LabelFrame , Menubutton , PanedWindow , Radiobutton , Scale , Scrollbar , and Spinbox . The other six are new: Combobox , Notebook , Progressbar , Separator , Sizegrip and Treeview .

What is the best way to show data in a table in Tkinter?

Luckily, there are alternate methods for creating a table to display data in Tkinter. For example, the Entry widget can be coded to display data in a table, and there are also table packages that can be downloaded from the Python Package Index (PyPI) and installed.

How does Python display data in GUI?

To display data we have to use insert() function. insert function takes two parameters. In our program, we have used entry widgets to capture the information provided by the user, and then we have to frame a sentence & that sentence is displayed in another Entry widget.


2 Answers

You can use Tkinter's grid.

To create a simple excel-like table:

try:     from tkinter import *  except ImportError:     from Tkinter import *  root = Tk()  height = 5 width = 5 for i in range(height): #Rows     for j in range(width): #Columns         b = Entry(root, text="")         b.grid(row=i, column=j)  mainloop() 

You can grab the data by accessing the children of the grid and getting the values from there.

like image 192
Steven Avatar answered Sep 20 '22 06:09

Steven


Tkinter doesn't have a built-in table widget. The closest you can use is a Listbox or a Treeview of the tkinter's sub package ttk.

However, you can use tktable, which is a wrapper around the Tcl/Tk TkTable widget, written by Guilherme Polo. Note: to use this wrapper library you need first to have installed the original Tk's TkTable library, otherwise you will get an "import error".

like image 38
Sticky Avatar answered Sep 21 '22 06:09

Sticky