Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GUI Python interfaces and DataGrids

940 views
Skip to first unread message

Maan Hamze

unread,
Aug 25, 2001, 2:32:51 PM8/25/01
to
Unless I am missing something, I have looked and I Tkinter does not seem to
have a DataGrid to receive the rows of a query (a dataset) and display them
or to bind it into a dataset. There is the Python DB API after all. So I
believe the issue of Datasets should be standardized across the different
database packages.
Now, I believe I have an idea on how to build a class and use it in Python
that can do exactly this.
But does Tkinter have a DataGrid? If not, are there any other GUI Python
packages that come with a DataGrid?
Maan

Boudewijn Rempt

unread,
Aug 25, 2001, 3:30:14 PM8/25/01
to

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

Joseph Andrew Knapka

unread,
Aug 25, 2001, 4:10:29 PM8/25/01
to
Boudewijn Rempt wrote:
>
> Maan Hamze <mmh...@pleiades.net> wrote:
> > Unless I am missing something, I have looked and I Tkinter does not seem to
> > have a DataGrid to receive the rows of a query (a dataset) and display them
> > or to bind it into a dataset. There is the Python DB API after all. So I
> > believe the issue of Datasets should be standardized across the different
> > database packages.
> > Now, I believe I have an idea on how to build a class and use it in Python
> > that can do exactly this.
> > But does Tkinter have a DataGrid? If not, are there any other GUI Python
> > packages that come with a DataGrid?
>
> 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.

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

Maan Hamze

unread,
Aug 25, 2001, 5:12:24 PM8/25/01
to
Thanks Joseph. This is what I had in mind (or something along these lines)
by way of doing my own grid for a dataset.
Maan

"Joseph Andrew Knapka" <jkn...@earthlink.net> wrote in message
news:3B87B147...@earthlink.net...

Maan Hamze

unread,
Aug 25, 2001, 5:25:20 PM8/25/01
to
Just out of curiousity:

you said:
> 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.

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...

Boudewijn Rempt

unread,
Aug 27, 2001, 4:48:51 AM8/27/01
to
Maan Hamze wrote:

> 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

unread,
Aug 27, 2001, 5:00:50 AM8/27/01
to
Joseph Andrew Knapka wrote:

> 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

0 new messages