473,395 Members | 1,558 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 17595
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dean | last post by:
Hi All, I was checking out the demos for tk 8.4.4.0 and noticed that alot of them (e.g. the scrollbar) have the XP style. I also noticed that when I use Python 2.3 and a seperately installed...
4
by: Patrick L. Nolan | last post by:
Our Tkinter application has a big ScrolledText widget which is a log of everything that happens. In order to prevent people from making changes, we have it in DISABLED mode except when the...
1
by: syed_saqib_ali | last post by:
Please take a look at and run the code snippet shown below. It creates a canvas with vertical & Horizontal scroll-bars. If you shrink the window to smaller than the area of the canvas, the...
3
by: Matt Hammond | last post by:
Here's a strange one in Tkinter that has me stumped: (I'm running python 2.4 on Suse Linux 9.3 64bit) I'm trying to make a set of Entry widgets with Label widgets to the left of each one, using...
3
by: H J van Rooyen | last post by:
Hi, Still struggling with my GUI exercise - I have the following lines of code in a routine that is bound at <Key-Returnto an instance of Entry : self.disp.Amount_des = Label(self.disp,...
2
by: jim-on-linux | last post by:
py help, The file below will run as a stand alone file. It works fine as it is. But, when I call it from another module it locks my computer, The off switch is the only salvation. This...
1
by: 3056kgw | last post by:
I'm fairly new to programming GUI's and I'm trying to control the zoom of a figure from matplotlib using a scrollbar. I can create the canvas for the figure with... import matplotlib import...
6
by: Adam | last post by:
Hey, I'm pretty new to programming. Been trying to learn using Python. The code I'm struggling with is for my GUI. I'm am having trouble getting this to display the way I want with the grid...
2
by: Appu2008 | last post by:
HI, Iam creating a python application using Tkinter. Ia trying to attach a scrollbar to a listbox. Please tell me how can i set the height of the scrollbar to that of the listbox. Beacuse in...
2
by: goldtech | last post by:
Hi, I'm stumped on how to have a scrollbar with a long list of checkboxes. Given code like: from Tkinter import * root = Tk() states = for i in range(150): var = IntVar()
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.