python中的多行文本输入框

And*_*tig 1 tkinter python-3.x

在python中,我一直在制作像Microsoft word这样的文本编辑器,但是我不知道如何制作文本输入框供用户输入。这是我的代码!(ps,谢谢!)

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()
Run Code Online (Sandbox Code Playgroud)

pha*_*tom 6

您可以这样做:

TextArea = Text()
TextArea.pack(expand=YES, fill=BOTH)
Run Code Online (Sandbox Code Playgroud)

如果要使用滚动条:

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)
Run Code Online (Sandbox Code Playgroud)

希望这有帮助,祝你好运!