473,804 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get ScrollRegion to adjust w/ window-size?

Below is a simple code snippet showing a Tkinter Window bearing a
canvas and 2 connected scrollbars (Vertical & Horizontal). Works fine.
When you shrink/resize the window the scrollbars adjust accordingly.

However, what I really want to happen is that the area of the canvas
that the scrollbars show (the Scrollregion) should expand as the window
grows. It doesn't currently do this. although, if the window shrinks
smaller than the original canvas-size, then the scrollregion adjusts
properly.

How can I make it such that the Scrollregion fills the entire space
avaialable to it. I tried all permutations of setting
expand=Tkinter. YES and fill=Tkinter.BO TH in the pack command??

-Saqib

----------------------------------------------------

import Tkinter

class testApp2:

def _setupCanvas(se lf):
self._canvasFra me = Tkinter.Frame(s elf._overallFra me, bd=1,
relief=Tkinter. SUNKEN)
self._canvasFra me.pack(expand= Tkinter.YES, fill=Tkinter.BO TH)

self._canvas = Tkinter.Canvas( self._canvasFra me,
background="whi te", width=self._can vasWidth,
height=self._ca nvasHeight,)

# Scroll Bars
vScrollbar = Tkinter.Scrollb ar(self._canvas Frame)
hScrollbar = Tkinter.Scrollb ar(self._canvas Frame)

# Scroll Bars
vScrollbar = Tkinter.Scrollb ar(self._canvas Frame)
vScrollbar.pack (side=Tkinter.L EFT, expand=Tkinter. NO,
fill=Tkinter.NO NE)

hScrollbar = Tkinter.Scrollb ar(self._canvas Frame)
hScrollbar.pack (side=Tkinter.T OP, expand=Tkinter. NO,
fill=Tkinter.NO NE)

# Configure
self._parent.ro wconfigure(0, weight=1)
self._parent.co lumnconfigure(0 , weight=1)
# self._scrollX0 = self._scrollY0 = 0
# self._scrollX1 = self._canvasWid th
# self._scrollY1 = self._canvasHei ght

print "self._canvasWi dth = %s" % self._canvasWid th
print "self._canvasHe ight = %s" % self._canvasHei ght
# print "self._scro llX1 = %s" % self._scrollX1
# print "self._scro llY1 = %s" % self._scrollY1
self._canvas.co nfig(
width=self._can vasWidth,
height=self._ca nvasHeight,
scrollregion=(0 ,0, self._canvasWid th, self._canvasHei ght),
yscrollcommand= vScrollbar.set,
xscrollcommand= hScrollbar.set,
)

vScrollbar.conf ig(orient=Tkint er.VERTICAL,
command=self._c anvas.yview)
hScrollbar.conf ig(orient=Tkint er.HORIZONTAL,
command=self._c anvas.xview)

self._canvasFra me.pack()
self._canvas.pa ck(expand=Tkint er.YES, fill=Tkinter.BO TH)
vScrollbar.pack (side=Tkinter.R IGHT, expand=Tkinter. YES,
fill=Tkinter.Y)
hScrollbar.pack (side=Tkinter.B OTTOM, expand=Tkinter. YES,
fill=Tkinter.X)

def __init__(self, parent):
self._parent = parent

self._overallFr ame = Tkinter.Frame(s elf._parent, bd=1,
relief=Tkinter. SUNKEN)
self._overallFr ame.pack(expand =Tkinter.YES, fill=Tkinter.BO TH)

self._canvasWid th = 300
self._canvasHei ght = 250
self._setupCanv as()
self._setCallBa cks()

def _setCallBacks(s elf):
# Function Bindings
self._canvas.bi nd("<Button-1>", self._b1PressEv t)

def _b1PressEvt(sel f, event):
print self._canvas.co nfig('scrollreg ion')
print self._canvas.co nfig('width')
print self._canvas.co nfig('height')
print "=" * 50
print "\n"

root = Tkinter.Tk()
app = testApp2(root)
root.mainloop()

Aug 5 '05 #1
1 12365
The ScrollRegion of the canvas gives the area that should be "available"
for scrolling. If this is larger than the visible area of the canvas,
then associated scrollbars will allow scrolling. If this is smaller
than the visible area of the canvas, then the scrollbar will fill with
the "thumb" and no scrolling is possible.

Here is an application that creates a 5000x5000 canvas and allows
scrolling. The scrollbars react appropriately when the window is
resized.
from Tkinter import *

t = Tk()

c = Canvas(t)
hsb = Scrollbar(t, orient="h", command=c.xview )
vsb = Scrollbar(t, orient="v", command=c.yview )
c.configure(ysc rollcommand=vsb .set, xscrollcommand= hsb.set)

c.grid(row=0, column=0, sticky="nsew")
hsb.grid(row=1, column=0, stick="ew")
vsb.grid(row=0, column=1, sticky="ns")

t.grid_rowconfi gure(0, weight=1)
t.grid_columnco nfigure(0, weight=1)

c.configure(scr ollregion = (0, 0, 5000, 5000))

for x in range(100, 5000, 100):
for y in range(100, 5000, 100):
c.create_text(( x,y), anchor=CENTER, text="%d,%d" % (x,y))

t.mainloop()

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

iD8DBQFC9KY1Jd0 1MZaTXX0RAntrAJ oD3rZ5Se/OdyhC+xkU1nJkMp TITwCfeOEF
I2rrOgXzrusVp9r MYRBXcBU=
=AWaw
-----END PGP SIGNATURE-----

Aug 6 '05 #2

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

Similar topics

3
19137
by: dreamer | last post by:
I am making a program for a friend with a disability. I need to adjust his audio volume using the keyboard as he cannot use a mouse. Any suggestions as to how I can raise the volume using the up arrow on the keyboard and decrease the volume using the down arrow? I am using VB 5. Many thanks in advance.
0
1629
by: Jeff O. | last post by:
Has anyone written a class to adjust their Timer period for daylight savings time? Or, is there another way to have the timer automatically adjust for DST?
3
10975
by: Ethan | last post by:
I have a form that contains sets of checkboxes. Each set has links above it marked "Check all" and "Uncheck all". The links call JavaScript functions. Here's the problem. When you click "Check all" and it's near the bottom of the page, the page is RELOADED and the user winds up looking at the top of the page. Sure, all the boxes are properly checked, but now the user has to scroll back down to where they were before. It's easy enough...
10
1727
by: Jarson | last post by:
I am using the ACRONYM tag to provide an explanation of codes within my application. Example: <p>The circuit <acronym title="Circuit P123T: Picton SS to Telebary SS 345KV">P123T</acronym> is out of service from 13:00 to 15:00 today</p>. I would prefer a fancy balloon tip, but this allows me to store and retrieve the text directly in a database table, and avoid having to add any additional setup text to create any invisible balloon...
2
2841
by: Elijsh | last post by:
I'm new to datagrid and VB.Net. Is there any way to adjust the height of datagrid textbox row according to the height of text programmatically ? I mean I have multiple data with varied length, some have one rows, some have three rows and maybe seven. How can I set the height programmaticalky? Your advice is greatly appreciated!
3
2531
by: mistral | last post by:
Here is javscript clock: http://javascript.internet.com/time-date/mousetrailclock.html which I want adjust a little: 1. I want replace the days of week/year/date in external circle with just custom text: 'www.company.com' 2. I want to reduce a little rotation speed of this text. 3. I want to fix a clock in some place, no need in mouse trail effect.
3
7336
by: Q. John Chen | last post by:
I have a page contains a table (e.g a 3-row table). The middle row is for the content and the bottom row is for footer notes. When the middle row does not have much info, the footer goes way too high up. How can I automatically adjust the height of the middle row when a user re-size the browser window. Or, how can specify a minimum height so at least the footer is a footer?
6
8126
by: Christopher Glenn | last post by:
I have very basic html skills. My friend who has a wide screen monitor and is using IE7 sent me a jpg screen shot of my home page. I have attached this jpg, but I recall a while back that attachments were discouraged. I am sorry if I have offended anyone by attaching. Note the left side table tiles or repeats towards the right side of the screen, but the text does not, so it cannot be seen under the graphic.
0
1321
by: daddyb1 | last post by:
RE: http://www.thescripts.com/forum/thread491642.html ###email removed### May 16th, 2006 10:35 AM Hi, Using Console.Writeline, as while ((strLine = stream.ReadLine()) != null) { sb.Append(strLine); Console.WriteLine(strLine); } this writes all the data to the screen at one go. Is there away to
12
2791
by: icarus | last post by:
platform: windows xp professional, python 2.5, wxpython When I double-check on my program file test.py (for simplicity I'll be using this code below), I see the window just fine. But the ms-dos black window pops up in the background. On Linux, no issues at all. How can I get rid of that ms-dos black window in the background? something I need to add to my code? a setting to adjust in windows? thanks in advance.
0
9714
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
10600
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
10351
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
10096
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...
1
7638
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5534
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
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3834
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.