Tkinter/scrollbar/canvas question

Discussion in 'Python' started by agb, Jun 22, 2011.

  1. agb

    agb Guest

    Dear Pythonistas,

    I've been trying to write a script that results in a set of widgets in a
    scrollable widget. Since tkinter is "the" gui for Python (and about the
    only one that I can be sure will not require additional software
    installation), I went that route, and wrote the following:

    from tkinter import *
    class ShowList(Frame):
    def __init__(self, root):
    Frame.__init__(self, root)
    self.grid()
    self.draw_widgets()
    def draw_widgets(self):
    cframe = Frame()
    cframe.grid(row=1, sticky=N+S+E+W)
    canv = Canvas(cframe)
    canv["scrollregion"]=canv.bbox(ALL)
    canv.grid(row=0, column=0, sticky=N+S+E+W)
    vscroll = Scrollbar(cframe, orient=VERTICAL, command=canv.yview)
    hscroll = Scrollbar(cframe, orient=HORIZONTAL, command=canv.xview)
    vscroll.grid(row=0, column=1, sticky=N+S)
    hscroll.grid(row=1, column=0, sticky=E+W)
    canv["xscrollcommand"] = hscroll.set
    canv["yscrollcommand"] = vscroll.set
    aframe = Frame(canv)
    canv.create_window(0,0,window=aframe, anchor=N+W)
    for i in range(0,100):
    Label(aframe, text=str(i), anchor=N+W).grid(row=i, column=0)

    root = Tk()
    m=ShowList(root)
    root.mainloop()


    ....which is great in that it does display the list of items (in this case, a
    bunch of Labels) but not so great in the fact that the vertical scrollbar's
    scroll thumb is the list of the entire scroll trough, making skip down/up a
    screenful impossible. Both the horizontal scrollbar and the vertical
    scrollbar will scroll until the list is off the screen (not the desired
    behavior).

    Initially, I thought the canv["scrollregion"] = canv.bbox(ALL) would take
    care of the off-screen scrolling by making the scrollable region no larger
    than it needs to be. Reading many examples of Python+tkinter code, intended
    to demonstrate the way to code scrollbars and canvases, didn't enlighten me
    enough to figure out the bug(s) in my code. Any suggestions as to what I
    did wrong?

    Many thanks in advance,

    --agb

    --
    http://gall.mine.nu
    free to get comics,free chat-1,dc++ (dcplusplus),
    mute webcache,group update program,torrent,atomic time server,tool to find your ip
     
    agb, Jun 22, 2011
    #1
    1. Advertising

  2. On Wed, Jun 22, 2011 at 1:50 PM, Saul Spatz <> wrote:
    > This is the third time I've tried to post this reply.  If you see multiple answers from me, that's why.
    >


    All three came through on the mailing list, but out of order - this
    one came in second.

    Chris Angelico
     
    Chris Angelico, Jun 22, 2011
    #2
    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. Gary Richardson

    Tkinter Canvas/Grid question

    Gary Richardson, Sep 11, 2003, in forum: Python
    Replies:
    6
    Views:
    3,086
    Jeff Epler
    Sep 12, 2003
  2. Askari
    Replies:
    2
    Views:
    715
    Askari
    Aug 30, 2004
  3. PhilC
    Replies:
    2
    Views:
    896
    PhilC
    Oct 25, 2004
  4. Alex

    ScrollBar? Does it exist just WEB ScrollBar Control?

    Alex, Apr 1, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    273
    Alvin Bruney [MVP]
    Apr 4, 2004
  5. Replies:
    10
    Views:
    268
    Rick Johnson
    Mar 15, 2013
Loading...

Share This Page