Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Python Tkinter - Entry Widget
Next article icon
Tkinter is a built-in standard python library. With the help of Tkinter, many GUI applications can be created easily. There are various types of widgets available in Tkinter such as button, frame, label, menu, scrolledtext, canvas and many more. A widget is an element that provides various controls. ScrolledText widget is a text widget with a scroll bar. The tkinter.scrolledtext module provides the text widget along with a scroll bar. This widget helps the user enter multiple lines of text with convenience. Instead of adding a Scroll bar to a text widget, we can make use of a scrolledtext widget that helps to enter any number of lines of text.Example 1 :Python code displaying scrolledText widget.Python3
# Python program demonstrating# ScrolledText widget in tkinterimporttkinterastkfromtkinterimportttkfromtkinterimportscrolledtext# Creating tkinter main windowwin=tk.Tk()win.title("ScrolledText Widget")# Title Labelttk.Label(win,text="ScrolledText Widget Example",font=("Times New Roman",15),background='green',foreground="white").grid(column=0,row=0)# Creating scrolled text# area widgettext_area=scrolledtext.ScrolledText(win,wrap=tk.WORD,width=40,height=10,font=("Times New Roman",15))text_area.grid(column=0,pady=10,padx=10)# Placing cursor in the text areatext_area.focus()win.mainloop()
Output :Scrolledtext widgetExample 2 :ScrolledText widget making tkinter text Read only.Python3
# Importing required modulesimporttkinterastkimporttkinter.scrolledtextasst# Creating tkinter windowwin=tk.Tk()win.title("ScrolledText Widget")# Title Labeltk.Label(win,text="ScrolledText Widget Example",font=("Times New Roman",15),background='green',foreground="white").grid(column=0,row=0)# Creating scrolled text area# widget with Read only by# disabling the statetext_area=st.ScrolledText(win,width=30,height=8,font=("Times New Roman",15))text_area.grid(column=0,pady=10,padx=10)# Inserting Text which is read onlytext_area.insert(tk.INSERT,"""\This is a scrolledtext widget to make tkinter text read only.HiGeeks !!!Geeks !!!Geeks !!!Geeks !!!Geeks !!!Geeks !!!Geeks !!!""")# Making the text read onlytext_area.configure(state='disabled')win.mainloop()
Output :scrolledtext_widgetIn the first example, as you can see the cursor, the user can enter any number of lines of text. In the second example, the user can just read the text which is displayed in the text box and cannot edit/enter any lines of text. We may observe that the scroll bar disappears automatically if the text entered by the user is less than the size of the widget.

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