I want a Excel like table widget in tkinter for a gui I am writing. Do you have any suggestions?
3 Answers
You can use Tkinter to make a simple spreadsheet-like GUI:
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()
If you want to get the values from the grid, you can use the grid's children.
def find_in_grid(frame, row, column):
for child in frame.children.values():
info = child.grid_info()
if info['row'] == row and info['column'] == column:
return child
return None
The function will return the child. To get the value of the entry, you can use:
find_in_grid(root, i+1, j).get()
Note: In old versions of Tkinter, row and column are stored as strings, so there you'd need to cast the integers:
if info['row'] == str(row) and info['column'] == str(column):

- 54,589
- 14
- 104
- 138

- 790
- 7
- 16
-
I'm glad for your starting point, but it doesn't work unless you also use `StringVar` for each `Entry` – nmz787 Mar 08 '18 at 02:12
Tktable is at least arguably the best option, if you need full table support. Briefly, the following example shows how to use it assuming you have it installed. The example is for python3, but for python2 you only need to change the import statement.
import tkinter as tk
import tktable
root = tk.Tk()
table = tktable.Table(root, rows=10, cols=4)
table.pack(side="top", fill="both", expand=True)
root.mainloop()
Tktable can be difficult to install since there is no pip-installable package.
If all you really need is a grid of widgets for displaying and editing data, you can easily build a grid of entry or label widgets. For an example, see this answer to the question Python. GUI(input and output matrices)?

- 1
- 1

- 370,779
- 53
- 539
- 685
-
2Hey,I am a little confused.Which file should i download and put it in which directory ? – IordanouGiannis Aug 26 '11 at 19:57
-
2
-
I had a similar problem trying to show a complete panda's DataFrame using tkinter. My first option was to create a grid like suggested someone in the first answer, but it bacame too heavy for so many info.
I guess is beter to create a finite numbers of cells and show only a part of the DF, changing that part with the movement of the user