In this TKinter Python article i want to show you How To Create ScrollTextArea In TKinter
so you can read my previous articles on Python TKinter GUI Development.
Also you can read more articles on Python GUI Development
1: PyQt5 GUI Development Tutorials
2: Pyside2 GUI Development Tutorials
3: wxPython GUI Development Tutorials
4: Kivy GUI Development Tutorials
So first of all this is the complete code for creating ScrollTextArea in tkinter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import tkinter as tk from tkinter import scrolledtext class Window(tk.Tk): def __init__(self): tk.Tk.__init__(self) self.title("Tkinter Scrolled Text Controll") self.minsize(600, 400) self.wm_iconbitmap('icon.ico') self.scrolledTextCtrl() def scrolledTextCtrl(self): scroll_w = 30 scroll_h = 10 scrollText = scrolledtext.ScrolledText(self, width = scroll_w, height = scroll_h, wrap = tk.WORD) scrollText.grid(column = 0, columnspan = 3) window = Window() window.mainloop() |
So in this part we have used Object Oriented Programming (OOP), we have created a class that extends from tk.TK and we have added our window title, window size and window icon in the constructor of the class, make sure that you have added an icon to your working directory. also we have called our scrollTextControl() method in this class.
1 2 3 4 5 6 7 8 |
class Window(tk.Tk): def __init__(self): tk.Tk.__init__(self) self.title("Tkinter Scrolled Text Controll") self.minsize(600, 400) self.wm_iconbitmap('icon.ico') self.scrolledTextCtrl() |
In this method first we have created two variables for the width and height of ScrollTextArea, because in the constructor of the ScrollTextArea we need to pass these values. after that you need to create the ScrollTextArea and add those width and height.
1 2 3 4 5 6 7 8 |
def scrolledTextCtrl(self): scroll_w = 30 scroll_h = 10 scrollText = scrolledtext.ScrolledText(self, width = scroll_w, height = scroll_h, wrap = tk.WORD) scrollText.grid(column = 0, columnspan = 3) |
Run the complete source code and this will be the result.
Also you can watch the complete video for this article
Subscribe and Get Free Video Courses & Articles in your Email