By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,704 Members | 1,122 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,704 IT Pros & Developers. It's quick & easy.

Tkinter: scrollbar in grid-managed frame

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.