Not if you mean a ready-made data-aware grid control like Visual Basic
has. You'll have to roll your own. One problem is that Tkinter, to the
best of my knowledge doesn't have a grid control at all. I know that
both wxPython and PyQt have a good grid control, and filling a table
yourself from the results of a query is easy enough, and gives you a
lot of flexibility. In fact, at the last VB shop where I worked, use
of data-aware controls was forbidden: we had to fill the grids
ourselves anyway.
--
Boudewijn Rempt | http://www.valdyas.org
True, but the grid layout manager makes it extremely easy
to create one.
from Tkinter import *
class SequenceGridException:
pass
class SequenceGrid(Frame):
def __init__(self,parent,**kw):
Frame.__init__(self,parent,**kw)
self.fields = []
self.rows = 0
self.cols = 0
def setRows(self,rows):
self.rows = 0
self.cols = 0
for field in self.fields:
field.grid_forget()
field.destroy()
self.fields = []
for row in rows:
self.cols = 0
for item in row:
txt = str(item)
field = Text(self,height=1,width=len(txt))
field.insert("1.0",txt)
field.grid(row=self.rows,col=self.cols,sticky="nsew")
self.fields.append(field)
self.cols += 1
self.rows += 1
def getItem(self,row,col):
if row < 0 or col < 0 or row >= self.rows or col >= self.cols:
raise SequenceGridException
idx = row * self.cols + col
return self.fields[idx].get("1.0","end")
# Test code:
test = 0
data =
[["Hello","world",42],["I","love","Python!"],["Tkinter","rocks","the
house!"]]
def fill():
global test, data
try:
print "1,2 is %s"%sg.getItem(1,2)
except:
print "Oops, no data in grid 1,2"
sg.setRows(data)
data.append(["New","row",test])
test += 1
if __name__ == "__main__":
root = Tk()
sg = SequenceGrid(root,width=100,height=100)
sg.grid(sticky="nsew")
btn = Button(command=fill,text="Fill grid")
btn.grid()
root.mainloop()
[snip]
> I know that
> both wxPython and PyQt have a good grid control, and filling a table
> yourself from the results of a query is easy enough, and gives you a
> lot of flexibility. In fact, at the last VB shop where I worked, use
> of data-aware controls was forbidden: we had to fill the grids
> ourselves anyway.
>
> --
>
> Boudewijn Rempt | http://www.valdyas.org
--
# Joe Knapka
# "You know how many remote castles there are along the
# gorges? You can't MOVE for remote castles!" - Lu Tze re. Uberwald
# Linux MM docs:
http://home.earthlink.net/~jknapka/linux-mm/vmoutline.html
"Joseph Andrew Knapka" <jkn...@earthlink.net> wrote in message
news:3B87B147...@earthlink.net...
I use the DataGrid with Delphi 5 (I got into Delphi last year after doing
work in VB) and it does save lots of time. Although at times I do my own
data grid. But why was it forbidden where you work?
I can not make up my mind whether Tkinter should come with a ready datagrid
that binds to a dataset. The dataset can be from
DatabaseQueryCursor.fetchone(), fetchmany() or fetchall(). On the other
hand, rolling our own datagrid (as I did, and as Joseph demonstrated) is
more dynamic. And allows more freedom. Maybe a DataGrid is for these lazy
moments when you need to demo something very fast. I can see a problem with
a Tkinter DataGrid when it comes to selecting a particular row or pointing
to a particular row. Here we will have integration issues between the
DataGrid and the Python DB API. too close for comfort come to think about
it. And maybe leaving it to the programmer to make their own DataGrid is
much better after all.
Maan
"Boudewijn Rempt" <bo...@rempt.xs4all.nl> wrote in message
news:9m8uc6$jpj$1...@news1.xs4all.nl...
> Just out of curiousity:
> I use the DataGrid with Delphi 5 (I got into Delphi last year after doing
> work in VB) and it does save lots of time. Although at times I do my own
> data grid. But why was it forbidden where you work?
Used to work... Using data-aware controls made for an unpredictable client
memory and database-server performance consumption, as well as for more
network traffic than we thought necessary.
--
Boudewijn | http://www.valdyas.org
> Boudewijn Rempt wrote:
>> Not if you mean a ready-made data-aware grid control like Visual Basic
>> has. You'll have to roll your own. One problem is that Tkinter, to the
>> best of my knowledge doesn't have a grid control at all.
>
> True, but the grid layout manager makes it extremely easy
> to create one.
>
Most GUI toolkits will have a grid layout manager where you can easily
make a grid out of arbitrary widgets - but that doesn't offer the
convenience of a good grid widget, where you can don't have to create
a separate widget for every cell, alternate colours between rows, have
a scrollbar to show where you are in the grid and things like that.
The PyQt grid is shown at:
http://doc.trolltech.com/table.html
And the wxPython at:
http://www.lpthe.jussieu.fr/~zeitlin/wxWindows/docs/wxwin172.htm#wxgrid
(with a picture at: http://wxpython.org/wxpshots.php)
--
Boudewijn | http://www.valdyas.org