- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Changing the appearance of a Scrollbar in Tkinter (using ttk styles)
Scrollbars are used to wrap an amount of text or characters in a frame or window. It provides a text widget to contain as many characters as the user wants.
The Scrollbar can be of two types: Horizontal Scrollbar and Vertical Scrollbar.
The length of a scrollbar changes whenever the number of characters in the Text widget increases. We can configure the style of Scrollbar by using ttk.Scrollbar. Ttk provides many inbuilt features and attributes that can be used to configure the Scrollbar.
Example
In this example, we will add a vertical scrollbar in a Text widget. We will use a ttk style theme to customize the look of the scrollbar. We have used here the 'classic' theme. Refer this link for a complete list ttk themes.
# Import the required libraries from tkinter import * from tkinter import ttk # Create an instance of Tkinter Frame win = Tk() # Set the geometry of Tkinter Frame win.geometry("700x250") style=ttk.Style() style.theme_use('classic') style.configure("Vertical.TScrollbar", background="green", bordercolor="red", arrowcolor="white") # Create a vertical scrollbar scrollbar = ttk.Scrollbar(win, orient='vertical') scrollbar.pack(side=RIGHT, fill=BOTH) # Add a Text Widget text = Text(win, width=15, height=15, wrap=CHAR, yscrollcommand=scrollbar.set) for i in range(1000): text.insert(END, i) text.pack(side=TOP, fill=X) # Configure the scrollbar scrollbar.config(command=text.yview) win.mainloop()
Output
Running the above code will display a window with a text widget and a customized vertical Scrollbar.
- Related Articles
- Changing ttk Button Height in Python
- Tkinter scrollbar for frame
- Changing the background color of a tkinter window using colorchooser module
- How to attach a vertical scrollbar to a Treeview using Tkinter?
- How to change the color of ttk button in Tkinter?
- Adding a scrollbar to a group of widgets in Tkinter
- How to get a horizontal scrollbar in Tkinter?
- Set a default value for a ttk Combobox in Tkinter?
- Changing Tkinter Label Text Dynamically using Label.configure()
- Configure tkinter/ttk widgets with transparent backgrounds
- Changing the Mouse Cursor in Tkinter
- How to attach a vertical scrollbar in Tkinter text widget?
- How to attach a Scrollbar to a Text widget in Tkinter?
- Changing the color a Tkinter rectangle on clicking
- Why do we use import * and then ttk in TKinter?
