473,324 Members | 2,400 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,324 software developers and data experts.

Tough Scrolling question with Tkinter

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!!

I want to know how to expand the size of a canvas without changing the
area/size of what is currently shown by the scroll bars. I would like
to find code that expands the width of the canvas and simply adjusts
the H-Scrollbar without changing what is shown on in the area of the
canvas being displayed.

I have tried seemingly every combination of messing with the
canvas.config and scrollregion parameters to no avail. Can someone out
there show me how its done??

-Saqib

-----------------------------------------
import Tkinter

def _b1PressEvt(event):
print "B1"
_canvas.config(width=300)

tkRoot = Tkinter.Tk()
_canvas = Tkinter.Canvas(tkRoot, background="white", width=200,
height=200,)

# Scroll Bars
vScrollbar = Tkinter.Scrollbar(tkRoot)
vScrollbar.pack(side=Tkinter.RIGHT, expand=True, fill=Tkinter.Y)

hScrollbar = Tkinter.Scrollbar(tkRoot)
hScrollbar.pack(side=Tkinter.BOTTOM, expand=True, fill=Tkinter.X)

_canvas.config(
width=200,
height=200,
scrollregion=(0,0,100,100),
yscrollcommand=vScrollbar.set,
xscrollcommand=hScrollbar.set,
)

vScrollbar.config(orient=Tkinter.VERTICAL, command=_canvas.yview)
hScrollbar.config(orient=Tkinter.HORIZONTAL, command=_canvas.xview)

#tkRoot.pack()
_canvas.pack(expand=Tkinter.NO)
vScrollbar.pack(side=Tkinter.RIGHT, expand=True, fill=Tkinter.Y)
hScrollbar.pack(side=Tkinter.BOTTOM, expand=True, fill=Tkinter.X)

# Function Bindings
_canvas.bind("<Button-1>", _b1PressEvt)

tkRoot.mainloop()

Jul 19 '05 #1
1 2936
Hi Saqib,

AFAIU, you want to change the scrollregion, not the size. So try:

def _b1PressEvt(event):
x0,y0,x1,y1 = canvas.config('scrollregion')[4]
print x0,y0,x1,y1
canvas.config(scrollregion=(int(x0),int(y0),int(x1 )+100,int(y1)))

First click will show nothing, because first change keeps the scrollregion
entirely in the window.

Eugene

<sy************@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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!!

I want to know how to expand the size of a canvas without changing the
area/size of what is currently shown by the scroll bars. I would like
to find code that expands the width of the canvas and simply adjusts
the H-Scrollbar without changing what is shown on in the area of the
canvas being displayed.

I have tried seemingly every combination of messing with the
canvas.config and scrollregion parameters to no avail. Can someone out
there show me how its done??

-Saqib

-----------------------------------------
import Tkinter

def _b1PressEvt(event):
print "B1"
_canvas.config(width=300)

tkRoot = Tkinter.Tk()
_canvas = Tkinter.Canvas(tkRoot, background="white", width=200,
height=200,)

# Scroll Bars
vScrollbar = Tkinter.Scrollbar(tkRoot)
vScrollbar.pack(side=Tkinter.RIGHT, expand=True, fill=Tkinter.Y)

hScrollbar = Tkinter.Scrollbar(tkRoot)
hScrollbar.pack(side=Tkinter.BOTTOM, expand=True, fill=Tkinter.X)

_canvas.config(
width=200,
height=200,
scrollregion=(0,0,100,100),
yscrollcommand=vScrollbar.set,
xscrollcommand=hScrollbar.set,
)

vScrollbar.config(orient=Tkinter.VERTICAL, command=_canvas.yview)
hScrollbar.config(orient=Tkinter.HORIZONTAL, command=_canvas.xview)

#tkRoot.pack()
_canvas.pack(expand=Tkinter.NO)
vScrollbar.pack(side=Tkinter.RIGHT, expand=True, fill=Tkinter.Y)
hScrollbar.pack(side=Tkinter.BOTTOM, expand=True, fill=Tkinter.X)

# Function Bindings
_canvas.bind("<Button-1>", _b1PressEvt)

tkRoot.mainloop()

Jul 19 '05 #2

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

Similar topics

0
by: Toph | last post by:
Bonjour a tous, Hi, I am developing a software in Python using Tkinter. The choice of my team is not to use pyton MegaWidgets. I would like to scroll a frame. This is a peace of my code : #...
1
by: Toph | last post by:
Hi, I am developing a software in Python using Tkinter. The choice of my team is not to use pyton MegaWidgets. I would like to scroll a frame. This is a peace of my code : #...
3
by: mksql | last post by:
I am re-orienting myself to GUI development (not having written anything but database routines that use simple command line interfaces for a long time now), and have become somewhat comfortable...
3
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...
0
by: syed_saqib_ali | last post by:
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...
1
by: Michael Yanowitz | last post by:
Hello: Below I have included a stripped down version of the GUI I am working on. It contains 2 dialog boxes - one main and one settings. It has the following problems, probably all related, that...
4
by: D | last post by:
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...
1
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...
4
by: BartlebyScrivener | last post by:
Using Python on Debian Etch. What is the best way to paste a block of text in at the command prompt. I'm trying something like: Quote = raw_input("Paste quote here: ") Which works great...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.