Tkinter Scrollbar not working

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dustan

    Tkinter Scrollbar not working

    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

    #2
    Re: Tkinter Scrollbar not working

    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).

    Comment

    • Martin Franklin

      #3
      Re: Tkinter Scrollbar not working

      Dustan wrote:[color=blue]
      > 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?
      >[/color]

      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="r ight", 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()


      Comment

      • Dustan

        #4
        Re: Tkinter Scrollbar not working


        Martin Franklin wrote:[color=blue]
        > Dustan wrote:[color=green]
        > > 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?
        > >[/color]
        >
        > 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)
        >[/color]

        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.
        [color=blue]
        >
        > ## 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="r ight", 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()[/color]

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

        Comment

        • Dustan

          #5
          Re: Tkinter Scrollbar not working

          Label Widget, sorry

          Comment

          • Martin Franklin

            #6
            Re: Tkinter Scrollbar not working

            Dustan wrote:[color=blue]
            > Martin Franklin wrote:
            >[color=green]
            >>Dustan wrote:
            >>[color=darkred]
            >>>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?
            >>>[/color]
            >>
            >>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)
            >>[/color]
            >
            >
            > 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.
            >
            >[color=green]
            >>## 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(sid e="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 ()[/color]
            >
            >
            > That doesn't help. I need to be able to do it either with a frame (has
            > content!) or a Text widget.
            >[/color]

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

            [color=blue]
            >C:/python24/python -u "quicksb.py "[/color]
            Traceback (most recent call last):
            File "quicksb.py ", line 17, in ?
            text['yscrollcommand '] = sb.set
            File "C:\python24\li b\lib-tk\Tkinter.py", line 1146, in __setitem__
            self.configure( {key: value})
            File "C:\python24\li b\lib-tk\Tkinter.py", line 1139, in configure
            return self._configure ('configure', cnf, kw)
            File "C:\python24\li b\lib-tk\Tkinter.py", line 1130, in _configure
            self.tk.call(_f latten((self._w , cmd)) + self._options(c nf))
            _tkinter.TclErr or: unknown option "-yscrollcommand"[color=blue]
            >Exit code: 1[/color]

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

            [color=blue]
            >C:/python24/python -u "quicksb.py "[/color]
            Traceback (most recent call last):
            File "quicksb.py ", line 17, in ?
            text['yscrollcommand '] = sb.set
            File "C:\python24\li b\lib-tk\Tkinter.py", line 1146, in __setitem__
            self.configure( {key: value})
            File "C:\python24\li b\lib-tk\Tkinter.py", line 1139, in configure
            return self._configure ('configure', cnf, kw)
            File "C:\python24\li b\lib-tk\Tkinter.py", line 1130, in _configure
            self.tk.call(_f latten((self._w , cmd)) + self._options(c nf))
            _tkinter.TclErr or: unknown option "-yscrollcommand"[color=blue]
            >Exit code: 1[/color]


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


            Cheers
            Martin

            Comment

            • Cameron Laird

              #7
              Re: Tkinter Scrollbar not working

              In article <1136233246.640 261.77260@g14g2 000cwa.googlegr oups.com>,
              Dustan <DustanGroups@g mail.com> wrote:[color=blue]
              >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).
              >[/color]

              That experience generalize poorly to comp.lang.pytho n.

              Comment

              • jmdeschamps@gmail.com

                #8
                Re: Tkinter Scrollbar not working


                Dustan a écrit :
                [color=blue]
                > 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?[/color]

                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 PythonMegaWidge ts (PMW)
                who have them I believe...

                Happy New Year anyhow...

                Jean-Marc

                Comment

                • Dustan

                  #9
                  Re: Tkinter Scrollbar not working

                  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.

                  Comment

                  Working...