Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
How to get selected value from listbox in tkinter?
Next article icon
Tkinter is the standard GUI library for Python. Tkinter in Python comes with a lot of good widgets. Widgets are standard GUI elements, and the Listbox, Scrollbar will also come under this Widgets.Note: For more information, refer toPython GUI – tkinter

Listbox

The ListBox widget is used to display different types of items. These items must be of the same type of font and having the same font color. The items must also be of Text type. The user can select one or more items from the given list according to the requirement.Syntax:
listbox = Listbox(root, bg, fg, bd, height, width, font, ..)
Adding-Scrollbar-to-ListBox-Python

Scrollbar

The scrollbar widget is used to scroll down the content. We can also create the horizontal scrollbars to the Entry widget.Syntax:The syntax to use the Scrollbar widget is given below.
w = Scrollbar(master, options)
Parameters:
  • master: This parameter is used to represents the parent window.
  • options: There are many options which are available and they can be used as key-value pairs separated by commas.
Adding-Scrollbar-to-ListBox-Python

Adding Scrollbar to ListBox

To do this we need to attach the scrollbar to Listbox, and to attach we use a functionlistbox.config() and set its command parameter to the scrollbar’s set method then set the scrollbar’s command parameter to point a method that would be called when the scroll bar position is changedPython3 1==
fromtkinterimport*# Creating the root windowroot=Tk()# Creating a Listbox and# attaching it to root windowlistbox=Listbox(root)# Adding Listbox to the left# side of root windowlistbox.pack(side=LEFT,fill=BOTH)# Creating a Scrollbar and# attaching it to root windowscrollbar=Scrollbar(root)# Adding Scrollbar to the right# side of root windowscrollbar.pack(side=RIGHT,fill=BOTH)# Insert elements into the listboxforvaluesinrange(100):listbox.insert(END,values)# Attaching Listbox to Scrollbar# Since we need to have a vertical# scroll we use yscrollcommandlistbox.config(yscrollcommand=scrollbar.set)# setting scrollbar command parameter# to listbox.yview method its yview because# we need to have a vertical viewscrollbar.config(command=listbox.yview)root.mainloop()
OutputAdding-Scrollbar-to-ListBox-Python

Improve
Article Tags :
Practice Tags :

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp