- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to attach a vertical scrollbar in Tkinter text widget?
The Scrollbar widget in tkinter is one of the useful widgets that is used to pack the container elements and their contents with a scrollbar. With Scrollbars, we can view large sets of data very efficiently.
Generally, Tkinter allows to add vertical and horizontal scrollbar in the application. By default, the vertical scrollbars are available in the constructor and we don't need to have an orientation for the scrollbar. To attach a vertical scrollbar in a Tkinter text widget, you can use xscrollcommand and yscrollcommmand to set the value of vertical and horizontal scrollbars.
# Import the required library from tkinter import * from tkinter import ttk from tkinter import messagebox # Create an instance of tkinter frame win=Tk() # Set the geometry win.geometry("700x350") # Add a Scrollbar(horizontal) v=Scrollbar(win, orient='vertical') v.pack(side=RIGHT, fill='y') # Add a text widget text=Text(win, font=("Georgia, 24"), yscrollcommand=v.set) # Add some text in the text widget for i in range(10): text.insert(END, "Welcome to Tutorialspoint...\n\n") # Attach the scrollbar with the text widget v.config(command=text.yview) text.pack() win.mainloop()
If we run the above code, it will display a text editor that will have some text in it. The text widget is packed with a vertical scrollbar and it gets executed whenever the text overflows in the text editor.
- How to attach a Scrollbar to a Text widget in Tkinter?
- How to attach a vertical scrollbar to a Treeview using Tkinter?
- Attach scrollbar to listbox as opposed to window in Tkinter
- How to highlight text in a tkinter Text widget?
- How to create hyperlink in a Tkinter Text widget?
- Vertical and Horizontal Scrollbars on Tkinter Widget
- Printing a list to a Tkinter Text widget
- How to erase everything from a Tkinter text widget?
- How do I center the text in a Tkinter Text widget?
- Add advanced features to a tkinter Text widget
- How to insert a temporary text in a tkinter Entry widget?
- Underline Text in Tkinter Label widget
- How to set default text for a Tkinter Entry widget?
- How to clear the contents of a Tkinter Text widget?
- How to take input in a text widget and display the text in tkinter?