-2

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.

sthiers
  • 3,489
  • 5
  • 34
  • 47

2 Answers2

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
  • This looks exactly like the answer I linked :-) – handle Jun 24 '16 at 13:48
  • 1
    You 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
  • 1
    tKinter 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