Python tkinter in a ListBox binding ScrollBar for Automatic loop scrolling

Source: Internet
Author: User

The last time I raised a question is how to achieve ScrollBar automatic scrolling (), after unremitting efforts finally solved the problem! Worth Celebrating ~ ~ ~

Not many words, the programmer or the last code comparison is real! Here is a small example:

from tkinter import* 


Class Tyst (Tk):
def __init__ (self):
tk.__init__:
Self.scrollbar = ScrollBar (self)
Self.scrollbar.pack (side = Right, fill=y)

Self.mylist = Listbox (self, yscrollcommand = self.scrollbar.set)

For line in range:
#self. Mylist.insert (END,STR)
Self.mylist.insert (END, "this Is line number "+ str"
Self.mylist.pack (side = left, fill = BOTH)

Self.scr Ollbar.config (Command = self.mylist.yview)


def main ():

Tyst = Tyst ()
for I In range:
Tyst.after (100,tyst.mylist.yview_moveto (i/100), Tyst.update ()) #滚动的同时要不停刷新

Tyst.mainloop ()

If __name__== ' __main__ ':
Main ()



Everyone should be able to see that the important place is here:
For I in range (100):        
Tyst.after (100,tyst.mylist.yview_moveto (i/100), Tyst.update ()) #滚动的同时要不停刷新

First, the Yview_moveto () function allows you to control the scroll bar, 1 for the entire scroll bar, such as you want him to scroll to half of the position you have to write Yview_moveto (0.5), and so on can use the loop to control it in different positions, notice a place,
Here, it must be Mylist.yview_moveto (), because you are already using MyList to bind the scroll bar, if you use another control to bind the scrollbar, is the "control name. Yview_moveto", and then, when you debug, you will find that If no update ()
To refresh, it will appear when the scroll bar is finished scrolling after the interface will appear, so be sure to remember to refresh with update ()! As for after I have not figured out how to use it, in fact, this place if you do not need after.

I hope this small example is helpful to everyone, if someone is more clear after how to use, hope to enlighten ~ ~


Python tkinter in a ListBox binding ScrollBar for Automatic loop scrolling

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.