In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use Scrollbar in Tkinter to achieve scroll bar related knowledge, the content is detailed and easy to understand, the operation is simple and fast, with a certain reference value, I believe you will have something to gain after reading this article on how to use Scrollbar in Tkinter to achieve scroll bar, let's take a look at it.
The previous article provided an encapsulated ScrollbarEx class, which greatly simplifies the use of Scrollbar controls. But this is not the way Tkinter envisioned it. The way Tkinter envisioned it was to bind it to other controls.
First build a label box control titled 'ScrollListBox'. This control is really too simple, so it's just a side note here.
Frame1 = LabelFrame (root, text='ScrollListBox') frame1.grid (row=0, column=0, columnspan=1, sticky=W+E)
Build a list box control.
# create a listbox for demo.lb = Listbox (frame1, activestyle='dotbox', height=8, width=20)
# add itemsfor i in range (0jue 20): lb.insert (END, str (I))
# bind eventlb.bind (', lambda e: label.config (text=str (lb.curselection () lb.grid (row=0, column=0)
Here's the point. The code first builds a vertical scroll bar and specifies command as the yview method of Listbox. Referring to the instructions in the previous article, you can imagine that the yview method should handle various scrolling notifications; in the previous article, when the location calculation is complete, you need to call the set method of Scrollbar, which is assigned to the yscrollcommand property of Listbox through the code.
Scroll_ly = Scrollbar (frame1, orient=VERTICAL, command=lb.yview) scroll_ly.grid (row=0, column=1, sticky=N+S) lb ['yscrollcommand'] = scroll_ly.set
In the same way, build the label box on the right:
Frame2 = LabelFrame (root, text='ScrollText') frame2.grid (row=0, column=1, columnspan=1, sticky=W+E+N+S)
Build a text control. Note that the wrap attribute is specified as NONE.
# create text widget.text = Text (frame2, height = 10, width=20, wrap=NONE) text.grid (row=0, column=0)
Build vertical and horizontal scroll bars, respectively:
Scroll_ty = Scrollbar (frame2, orient=VERTICAL, command=text.yview) scroll_ty.grid (row=0, column=1, sticky=N+S) text ['yscrollcommand'] = scroll_ty.set
Scroll_tx = Scrollbar (frame2, orient=HORIZONTAL, command=text.xview) scroll_tx.grid (row=1, column=0, sticky=E+W) text ['xscrollcommand'] = scroll_tx.set
If the wrap property of Text is not specified as NONE, the horizontal scroll bar will not work.
This is the end of the article on "how to use Scrollbar in Tkinter to implement scroll bars". Thank you for reading! I believe you all have a certain understanding of "how to use Scrollbar in Tkinter to achieve scroll bars". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.