Tkinter Scrollbar not working

Discussion in 'Python' started by Dustan, Jan 2, 2006.

  1. Dustan

    Dustan Guest

    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?
     
    Dustan, Jan 2, 2006
    #1
    1. Advertising

  2. Dustan

    Dustan Guest

    BTW, experience tells me it is necessary for me to explicitly state
    that I'm a newbie (otherwise I get rude people saying I should already
    know such-and-such).
     
    Dustan, Jan 2, 2006
    #2
    1. Advertising

  3. Dustan wrote:
    > 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?
    >


    It can be tricky getting an empty frame to scroll, can you post your
    example code so that we might be more helpful. Here is an example of
    binding a scroll bar to a Text widget (not exactly the same thing)


    ## import all names from Tkinter
    ## bit naughty but I don't mind
    from Tkinter import *


    # root window
    root=Tk()


    # text area
    text=Text()
    text.pack(side="left", expand="yes", fill="both")

    # scrolbar for above textarea
    sb = Scrollbar(root)
    sb.pack(side="right", fill="y")



    ## bind them both together...

    # this line binds the yscrollcommand
    # of the text area to the scrollbar set method
    text['yscrollcommand'] = sb.set

    # this line binds the scrollbars command to
    # the yview method of the text area
    sb['command'] = text.yview



    # mainloop entry
    root.mainloop()
     
    Martin Franklin, Jan 3, 2006
    #3
  4. Dustan

    Dustan Guest

    Martin Franklin wrote:
    > Dustan wrote:
    > > 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?
    > >

    >
    > It can be tricky getting an empty frame to scroll, can you post your
    > example code so that we might be more helpful. Here is an example of
    > binding a scroll bar to a Text widget (not exactly the same thing)
    >


    It's not an empty frame. It has a label. I was trying to do it with
    just the label, but it didn't work, and I figured it might be a better
    idea to try doing it with a frame instead.

    >
    > ## import all names from Tkinter
    > ## bit naughty but I don't mind
    > from Tkinter import *
    >
    >
    > # root window
    > root=Tk()
    >
    >
    > # text area
    > text=Text()
    > text.pack(side="left", expand="yes", fill="both")
    >
    > # scrolbar for above textarea
    > sb = Scrollbar(root)
    > sb.pack(side="right", fill="y")
    >
    >
    >
    > ## bind them both together...
    >
    > # this line binds the yscrollcommand
    > # of the text area to the scrollbar set method
    > text['yscrollcommand'] = sb.set
    >
    > # this line binds the scrollbars command to
    > # the yview method of the text area
    > sb['command'] = text.yview
    >
    >
    >
    > # mainloop entry
    > root.mainloop()


    That doesn't help. I need to be able to do it either with a frame (has
    content!) or a Text widget.
     
    Dustan, Jan 3, 2006
    #4
  5. Dustan

    Dustan Guest

    Label Widget, sorry
     
    Dustan, Jan 3, 2006
    #5
  6. Dustan wrote:
    > Martin Franklin wrote:
    >
    >>Dustan wrote:
    >>
    >>>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?
    >>>

    >>
    >>It can be tricky getting an empty frame to scroll, can you post your
    >>example code so that we might be more helpful. Here is an example of
    >>binding a scroll bar to a Text widget (not exactly the same thing)
    >>

    >
    >
    > It's not an empty frame. It has a label. I was trying to do it with
    > just the label, but it didn't work, and I figured it might be a better
    > idea to try doing it with a frame instead.
    >
    >
    >>## import all names from Tkinter
    >>## bit naughty but I don't mind
    >>from Tkinter import *
    >>
    >>
    >># root window
    >>root=Tk()
    >>
    >>
    >># text area
    >>text=Text()
    >>text.pack(side="left", expand="yes", fill="both")
    >>
    >># scrolbar for above textarea
    >>sb = Scrollbar(root)
    >>sb.pack(side="right", fill="y")
    >>
    >>
    >>
    >>## bind them both together...
    >>
    >># this line binds the yscrollcommand
    >># of the text area to the scrollbar set method
    >>text['yscrollcommand'] = sb.set
    >>
    >># this line binds the scrollbars command to
    >># the yview method of the text area
    >>sb['command'] = text.yview
    >>
    >>
    >>
    >># mainloop entry
    >>root.mainloop()

    >
    >
    > That doesn't help. I need to be able to do it either with a frame (has
    > content!) or a Text widget.
    >


    Perhaps I am not understanding something... can you please show me an
    example of what is not working. I consider the above a good recipe that
    can be applied to any scrollable widget in Tkinter.

    hmm, a single change to my example (Text to Frame) produces this
    traceback:-


    >C:/python24/python -u "quicksb.py"

    Traceback (most recent call last):
    File "quicksb.py", line 17, in ?
    text['yscrollcommand'] = sb.set
    File "C:\python24\lib\lib-tk\Tkinter.py", line 1146, in __setitem__
    self.configure({key: value})
    File "C:\python24\lib\lib-tk\Tkinter.py", line 1139, in configure
    return self._configure('configure', cnf, kw)
    File "C:\python24\lib\lib-tk\Tkinter.py", line 1130, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
    _tkinter.TclError: unknown option "-yscrollcommand"
    >Exit code: 1


    and another change (Frame to Label) produces this traceback:-


    >C:/python24/python -u "quicksb.py"

    Traceback (most recent call last):
    File "quicksb.py", line 17, in ?
    text['yscrollcommand'] = sb.set
    File "C:\python24\lib\lib-tk\Tkinter.py", line 1146, in __setitem__
    self.configure({key: value})
    File "C:\python24\lib\lib-tk\Tkinter.py", line 1139, in configure
    return self._configure('configure', cnf, kw)
    File "C:\python24\lib\lib-tk\Tkinter.py", line 1130, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
    _tkinter.TclError: unknown option "-yscrollcommand"
    >Exit code: 1



    This would suggest that the Frame and Label widgets are not scrollable
    (at least not in the 'y' direction)


    Cheers
    Martin
     
    Martin Franklin, Jan 3, 2006
    #6
  7. In article <>,
    Dustan <> wrote:
    >BTW, experience tells me it is necessary for me to explicitly state
    >that I'm a newbie (otherwise I get rude people saying I should already
    >know such-and-such).
    >


    That experience generalize poorly to comp.lang.python.
     
    Cameron Laird, Jan 3, 2006
    #7
  8. Dustan

    Guest

    Dustan a écrit :

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


    Frames are NOT scrollable objects for scrollbars in Tkinter: Listbox,
    Canvas and Text widget are.

    I f you want/need to scroll something else, I think you are going to
    have to do it yourself, meaning you can use the scrollbars to get user
    input by binding an event to it, and then moving things around your
    Frame to give the scrolling appearance.

    OR you can take a look at a third-party such as PythonMegaWidgets (PMW)
    who have them I believe...

    Happy New Year anyhow...

    Jean-Marc
     
    , Jan 3, 2006
    #8
  9. Dustan

    Dustan Guest

    Yes, I know PMW has scrolled Text, but the module has to be installed
    seperately; this is something I'm releasing to a number of people.

    I'll try doing it with a canvas.
     
    Dustan, Jan 3, 2006
    #9
    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. codecraig

    Tkinter and Scrollbar

    codecraig, Apr 19, 2005, in forum: Python
    Replies:
    0
    Views:
    363
    codecraig
    Apr 19, 2005
  2. Replies:
    1
    Views:
    1,006
  3. Alex

    ScrollBar? Does it exist just WEB ScrollBar Control?

    Alex, Apr 1, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    299
    Alvin Bruney [MVP]
    Apr 4, 2004
  4. Ross
    Replies:
    4
    Views:
    111
    Gérard Talbot
    Sep 29, 2005
  5. Sura
    Replies:
    0
    Views:
    105
Loading...

Share This Page