Search code examples
python-3.xtkinter

Multiple line text entry box in python


In python i have been making a text editor like Microsoft word but i don't know how to make a text entry box for the user to put input. Here is my code! (ps thank you!)

from tkinter import *
import sys


def doNothing():
    print("Test")


root = Tk()
root.title("TextEditor")
root.geometry("300x200")
menu = Menu(root)
root.config(menu=menu)

subMenu = Menu(menu)
menu.add_cascade(label="File", menu=subMenu)
subMenu.add_command(label="New Project...", command =doNothing)
subMenu.add_command(label="Save", command=doNothing)
subMenu.add_separator()

editMenu = Menu(menu)
menu.add_cascade(label="Edit", menu=editMenu)
editMenu.add_command(label="Undo",command=doNothing)

root.mainloop()

Solution

  • You can do that like this:

    TextArea = Text()
    TextArea.pack(expand=YES, fill=BOTH)
    

    If you want a scrollbar with it:

    TextArea = Text()
    ScrollBar = Scrollbar(root)
    ScrollBar.config(command=TextArea.yview)
    TextArea.config(yscrollcommand=ScrollBar.set)
    ScrollBar.pack(side=RIGHT, fill=Y)
    TextArea.pack(expand=YES, fill=BOTH)
    

    Hope this helped, good luck!