How to maintain scroll-region view while changing canvas size?

Discussion in 'Python' started by syed_saqib_ali@yahoo.com, Jun 7, 2005.

  1. Guest

    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()
    , Jun 7, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PhilC
    Replies:
    2
    Views:
    868
    PhilC
    Oct 25, 2004
  2. SAL

    #Region #End Region issue

    SAL, Aug 29, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    346
    Alexey Smirnov
    Aug 29, 2008
  3. Brent Burkart

    maintain column size while editing

    Brent Burkart, Sep 21, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    98
    Brent Burkart
    Sep 21, 2004
  4. Replies:
    0
    Views:
    148
  5. Replies:
    8
    Views:
    229
Loading...

Share This Page