w3resource

Python tkinter widgets Exercise: Create a ScrolledText widgets using tkinter module

Python tkinter widgets: Exercise-10 with Solution

Write a Python GUI program to create a ScrolledText widgets using tkinter module.

Sample Solution:

Python Code:

import tkinter as tk
import tkinter.scrolledtext as tkst
parent = tk.Tk()
parent.title("Scrolledtext")
parent.geometry('350x200')
txt = tkst.ScrolledText(parent, width=40, height=10)
txt.grid(column=0, row=0)
parent.mainloop()

Explanation:

In the exercise above -

  • import tkinter as tk - Import the Tkinter library (tkinter)
  • import tkinter.scrolledtext as tkst - Import the scrolled text widget (tkinter.scrolledtext).
  • Create the main Tkinter window (parent) with the title "Scrolledtext" and set its initial size to 350x200 pixels.
  • txt = tkst.ScrolledText(parent, width=40, height=10) - Create a ScrolledText widget (txt) that provides a scrollable text area.
  • txt.grid(column=0, row=0) - Use the grid() method to place the ScrolledText widget within the window, specifying its position by column and row.
  • parent.mainloop() - Start the Tkinter main loop to run the GUI application.

Sample Output:

Tkinter: Create a ScrolledText widgets using tkinter module

Flowchart:

Flowchart: Create a ScrolledText widgets using tkinter module

Python Code Editor:


Previous: Write a Python GUI program to create three radio buttons widgets using tkinter module.
Next: Write a Python GUI program to create a Progress bar widgets using tkinter module.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://198.211.115.131/python-exercises/tkinter/python-tkinter-widgets-exercise-10.php