How to draw (I mean graphically, not just print on console) a grid with data in it, like excel does it ? Just a matrix of strings displayed by row. I found nothing in Matplotlib.
Asked
Active
Viewed 9,103 times
-2
-
Yes, I spent 20 minutes to do so, and found nothing but plenty of matplotlib which does not answer the question: only scientific display which is not what I'm look for – sthiers Jun 24 '16 at 13:28
-
you could make a GUI using something like PythonCard – noɥʇʎԀʎzɐɹƆ Jun 24 '16 at 13:29
-
it's very easy to do such a thing in GUI. try tkinter – noɥʇʎԀʎzɐɹƆ Jun 24 '16 at 13:35
-
1You could use `openpyxl` to actually put it in an excel sheet... Are you asking how to write an excel-like program in python? – Will Jun 24 '16 at 13:35
-
No, I just want to display a bunch of rows in an grid (like an excel grid, or an html table) – sthiers Jun 24 '16 at 13:39
-
parse if with `pyxlrd` and write it as HTML? sounds pretty straightforward. – Maximilian Peters Jun 24 '16 at 13:44
-
Matplotlib has tables http://stackoverflow.com/questions/32137396/matplotlib-table-only – Phlya Jun 24 '16 at 13:47
-
http://stackoverflow.com/q/11047803/7432 – Bryan Oakley Jun 26 '16 at 02:31
2 Answers
4
If you want to create simple grid with some data you can use Tkinter
like this
from Tkinter import Tk, Entry, mainloop, StringVar
root = Tk()
height = 5
width = 5
for i in range(height): # Rows
for j in range(width): # Columns
text_var = StringVar()
# here we are setting cell text value
text_var.set('%s%s' % (i, j))
b = Entry(root, textvariable=text_var)
b.grid(row=i, column=j)
mainloop()

Kamil
- 2,712
- 32
- 39
-
Thanks. I never did gui in python - and did not know about tkinter. It's exactly what I was looking for. – sthiers Jun 24 '16 at 13:44
-
Maybe there is some better way to draw the grid with Python, but this is the fastest solution that I was able to create. – Kamil Jun 24 '16 at 13:47
-
-
1You don't need to use the `StringVar`, though it's harmless if you want to use it. It just adds one more object you have to manage. You should also give every row and column a weight and use the `sticky` attribute so that the widget behaves well when the window resizes. – Bryan Oakley Jun 26 '16 at 02:27
1
You are probably looking for a GUI toolkit that allows you to show a window with a data table that you can populate. I first thought of Qt's QListWidget that you could use via PyQt. But Python already comes with Tkinter, so you could continue your research at https://wiki.python.org/moin/GuiProgramming.

handle
- 5,859
- 3
- 54
- 82
-
1tKinter does not have a table widget, but see: http://stackoverflow.com/questions/9348264/does-tkinter-have-a-table-widget – handle Jun 24 '16 at 13:42