473,657 Members | 2,434 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tkinter Scrolling

D
I'm sure this is a simple question to the Tkinter experts - I have a
very basic Tkinter application that consists of 1 master window and
buttons within that window. My problem is that, I need to be able to
scroll (up and down) when I get to the point that the buttons go off
the screen. What's the easiest way to do this? Thanks in advance.

Feb 1 '07 #1
4 11477
On 2007-02-01 05:35:30 -0700, "D" <du********@hot mail.comsaid:
I'm sure this is a simple question to the Tkinter experts - I have a
very basic Tkinter application that consists of 1 master window and
buttons within that window. My problem is that, I need to be able to
scroll (up and down) when I get to the point that the buttons go off
the screen. What's the easiest way to do this? Thanks in advance.
The super-easiest way is to make the "background " a Text() widget, add
its scrollbars, then add the buttons and whatever else to it. Of
course you are then limited to the 'typewriter layout' of widget
placement. The typical way to do it is to make a scrolling canvas and
pack the buttons and other stuff into an empty Frame() and then pack
the frame on to the canvas, which I haven't had to do yet.

Bob

Feb 1 '07 #2
D

Bob Greschke wrote:
On 2007-02-01 05:35:30 -0700, "D" <du********@hot mail.comsaid:
I'm sure this is a simple question to the Tkinter experts - I have a
very basic Tkinter application that consists of 1 master window and
buttons within that window. My problem is that, I need to be able to
scroll (up and down) when I get to the point that the buttons go off
the screen. What's the easiest way to do this? Thanks in advance.

The super-easiest way is to make the "background " a Text() widget, add
its scrollbars, then add the buttons and whatever else to it. Of
course you are then limited to the 'typewriter layout' of widget
placement. The typical way to do it is to make a scrolling canvas and
pack the buttons and other stuff into an empty Frame() and then pack
the frame on to the canvas, which I haven't had to do yet.

Bob
Thanks, Bob - have you seen any examples of the latter approach (using
a canvas and frame)? Sounds rather confusing, but it definitely seems
like the approach I need to take. Thanks again.

Feb 1 '07 #3
On Thu, 01 Feb 2007 20:26:08 +0100, D <du********@hot mail.comwrote:
Bob Greschke wrote:
>The typical way to do it is to make a scrolling canvas and
pack the buttons and other stuff into an empty Frame() and then pack
the frame on to the canvas, which I haven't had to do yet.

Bob
Thanks, Bob - have you seen any examples of the latter approach (using
a canvas and frame)? Sounds rather confusing, but it definitely seems
like the approach I need to take. Thanks again.
Here you are:

-----------------------------------------------------------
from Tkinter import *

## Main window
root = Tk()
## Grid sizing behavior in window
root.grid_rowco nfigure(0, weight=1)
root.grid_colum nconfigure(0, weight=1)
## Canvas
cnv = Canvas(root)
cnv.grid(row=0, column=0, sticky='nswe')
## Scrollbars for canvas
hScroll = Scrollbar(root, orient=HORIZONT AL, command=cnv.xvi ew)
hScroll.grid(ro w=1, column=0, sticky='we')
vScroll = Scrollbar(root, orient=VERTICAL , command=cnv.yvi ew)
vScroll.grid(ro w=0, column=1, sticky='ns')
cnv.configure(x scrollcommand=h Scroll.set, yscrollcommand= vScroll.set)
## Frame in canvas
frm = Frame(cnv)
## This puts the frame in the canvas's scrollable zone
cnv.create_wind ow(0, 0, window=frm, anchor='nw')
## Frame contents
for i in range(20):
b = Button(frm, text='Button n#%s' % i, width=40)
b.pack(side=TOP , padx=2, pady=2)
## Update display to get correct dimensions
frm.update_idle tasks()
## Configure size of canvas's scrollable zone
cnv.configure(s crollregion=(0, 0, frm.winfo_width (), frm.winfo_heigh t()))
## Go!
root.mainloop()
-----------------------------------------------------------

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz 5(17l8(%,5.Z*(9 3-965$l7+-'])"
Feb 2 '07 #4
D
Here you are:
>
-----------------------------------------------------------
from Tkinter import *

## Main window
root = Tk()
## Grid sizing behavior in window
root.grid_rowco nfigure(0, weight=1)
root.grid_colum nconfigure(0, weight=1)
## Canvas
cnv = Canvas(root)
cnv.grid(row=0, column=0, sticky='nswe')
## Scrollbars for canvas
hScroll = Scrollbar(root, orient=HORIZONT AL, command=cnv.xvi ew)
hScroll.grid(ro w=1, column=0, sticky='we')
vScroll = Scrollbar(root, orient=VERTICAL , command=cnv.yvi ew)
vScroll.grid(ro w=0, column=1, sticky='ns')
cnv.configure(x scrollcommand=h Scroll.set, yscrollcommand= vScroll.set)
## Frame in canvas
frm = Frame(cnv)
## This puts the frame in the canvas's scrollable zone
cnv.create_wind ow(0, 0, window=frm, anchor='nw')
## Frame contents
for i in range(20):
b = Button(frm, text='Button n#%s' % i, width=40)
b.pack(side=TOP , padx=2, pady=2)
## Update display to get correct dimensions
frm.update_idle tasks()
## Configure size of canvas's scrollable zone
cnv.configure(s crollregion=(0, 0, frm.winfo_width (), frm.winfo_heigh t()))
## Go!
root.mainloop()
-----------------------------------------------------------

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz 5(17l8(%,5.Z*(9 3-965$l7+-'])"
Thanks, Eric - exactly what I needed!

Feb 2 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
10666
by: Jane Austine | last post by:
As you add more items, say text lines, in Text widget, it gets too slow and almost impractical to use on. Take idle for example. If the text gets bigger(e.g. print urllib.urlopen('http://www.amazon.com').read() ), it becomes too sluggish to use as an "interactive" shell. I have tried wxPython and it seems to have the same problem (from my experience using PyCrust). Is there any way to speed up Text widget, or should I look for another
3
2330
by: Bob Greschke | last post by:
I have a program where the user pushes a button, a "starting" message is ..inserted to a text field with an associated scroll bar, a thread is started that inserts a "working..." message on to the end of the text field until stopped, or until the loop finishes. The loop sleeps for about 3 seconds every time through (I'm just prototyping at this point). The mainloop just waits for the user to hit the same button again which will set a flag...
1
3847
by: corrado | last post by:
Hello I have an application running several thread to display some financial data; basically I have a thread displaying HTML tables by means of Tkhtml, another implementing a scrolling ticker based on a Text widget with embedded windows and a thread running the Tkinter mainloop plus several other thread dealing with the scheduling of the contents and the acquisition of data but not using graphic widgets. I run the same code on Linux...
1
2966
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 scroll-bars work as advertised. That's great. However, if you click the Left Mouse button, it calls code which expands the width of the canvas by 100 pixels. The area being viewed expands correspondingly..... BUT I DON'T WANT IT TO!!
8
11964
by: Dustan | last post by:
I'm trying to get a scrollbar bound with a Frame, and I keep on getting a scrollbar, but it doesn't actually scroll. Some help, please?
1
2978
by: Eric Wong | last post by:
Using Tkinter, I have a Canvas with vertical Scrollbar attached. At runtime, I dynamically create Checkboxes on the Canvas, each one on a different row. When I add a lot of Checkboxes, instead of the scrollbar kicking in, the Canvas resizes and subsequently, my Application window resizes such that it is larger than my monitor. Can I prevent the Canvas from resizing when I am creating widgets on it at runtime? I want to use the...
0
1471
by: aditya.siram | last post by:
Hi all, I recently found the Leo Outliner Tool (http://webpages.charter.net/edreamleo/front.html)written in Python and installed it on my Windows PC at work and my Debian and Ubuntu PC's at home. On my Linux installs, however, the application is jumpy. When scrolling down a long document in Leo, the redraw rate lags behind significantly as though the system is running out of memory. On Windows the scrolling is smooth and seamless. I...
1
2190
by: blackielawless | last post by:
Hi, My question is about scrolling canvas under Tkinter, I have a canvas of size 1280X800, where my plotting is way beyond the 1280,I need to add scroller bars H & V and be able to use them to pan around my image. Any help please Best regards
5
5224
by: goldtech | last post by:
I thought the "DISABLED" made it so I could not edit it. But it also makes it so I can not scroll down. If you make the window smaller than the content then try to put a cursor in there to use up/down arrow you can't. What I want is not to be able to change text content, but no other action is disabled. Is this complicated to do? Thanks.
0
8395
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8826
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7330
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.