468,272 Members | 2,176 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,272 developers. It's quick & easy.

Tkinter: scrollbar in grid-managed frame

anx
I've got a grid-managed frame, containing a column of Labels, and a
corresponding column of Entry widgets. I'd like to be able to display
dozens, or even hundreds of rows, and use a vertical scrollbar to
scroll through them in the frame. So far i can get a scrollbar to
display, but it won't scroll anything. So that's definately wrong. And
the columns just chop off at the bottom of the frame, but resizing the
window won't make the frame show more rows. Here's a rough sketch of
what i've done:

mw = Tk()
mainFrame = Frame( mw, borderwidth=5, relief=GROOVE, )
mainFrame.pack( side=TOP, anchor=N, expand=True, fill=BOTH, )

vertSB = Scrollbar( mainFrame, orient=VERTICAL, )
vertSB.grid( padx=1, column=0, rowspan=15, columnspan=1, sticky=NS, )
mainFrame.columnconfigure( 0, weight=1 )

Next i iterate through a simple dict, constructing a Label (in column
1) for each key, and an Entry (in column 2) for each value.

How do i make the Scrollbar fill all of column 0, no matter how many
rows are displayed, and stretch/shrink with mainFrame's size? Do i
have to catch resizing events, calculate how many rows are now
showing, and adjust rowspan?

How do i make my grid show more rows when i expand my window?

Am i going about this entirely the wrong way? Is grid the wrong
geometry manager to use for this frame?

Thanks,
E

--
Nov 22 '05 #1
2 16207
Tkinter "frame"s don't scroll. Instead, you need to use something like
bwidget's "ScrollableFrame" widget. You may want to combine this with
bwidget's "ScrolledWindow".

Below is an example which uses my "pybwidget" package, available at
http://tkinter.unpy.net/bwidget/
# ----------------------------------------------------------------------
import Tkinter, bwidget

t = Tkinter.Tk()
s = bwidget.ScrolledWindow(t, auto="vertical", scrollbar="vertical")
f = bwidget.ScrollableFrame(s, constrainedwidth=True)
g = f.getframe()

for i in range(20):
Tkinter.Label(g, text="Field %d: " % i).grid(row=i, column=0, sticky="w")
Tkinter.Entry(g, width=25).grid(row=i, column=1, sticky="ew")
g.grid_columnconfigure(1, weight=1)

s.setwidget(f)
s.pack(fill="both", expand=1)
t.mainloop()
# ----------------------------------------------------------------------

Jeff
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDe6kEJd01MZaTXX0RAqf+AJwJeqXh+1j4tiJakdM1SA 59kGccDgCeIUE/
elqfqeLfW2Q7nqsKN8qSpsQ=
=oicG
-----END PGP SIGNATURE-----

Nov 22 '05 #2
Tkinter "frame"s don't scroll. Instead, you need to use something like
bwidget's "ScrollableFrame" widget. You may want to combine this with
bwidget's "ScrolledWindow".

Below is an example which uses my "pybwidget" package, available at
http://tkinter.unpy.net/bwidget/
# ----------------------------------------------------------------------
import Tkinter, bwidget

t = Tkinter.Tk()
s = bwidget.ScrolledWindow(t, auto="vertical", scrollbar="vertical")
f = bwidget.ScrollableFrame(s, constrainedwidth=True)
g = f.getframe()

for i in range(20):
Tkinter.Label(g, text="Field %d: " % i).grid(row=i, column=0, sticky="w")
Tkinter.Entry(g, width=25).grid(row=i, column=1, sticky="ew")
g.grid_columnconfigure(1, weight=1)

s.setwidget(f)
s.pack(fill="both", expand=1)
t.mainloop()
# ----------------------------------------------------------------------

Jeff
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDe6kEJd01MZaTXX0RAqf+AJwJeqXh+1j4tiJakdM1SA 59kGccDgCeIUE/
elqfqeLfW2Q7nqsKN8qSpsQ=
=oicG
-----END PGP SIGNATURE-----

Nov 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Dean | last post: by
4 posts views Thread by Patrick L. Nolan | last post: by
1 post views Thread by syed_saqib_ali | last post: by
3 posts views Thread by Matt Hammond | last post: by
3 posts views Thread by H J van Rooyen | last post: by
6 posts views Thread by Adam | last post: by
2 posts views Thread by goldtech | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.