30

Entry widgets seem only to deal with single line text. I need a multiline entry field to type in email messages.

Anyone has any idea how to do that?

Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
xiaolong
  • 3,396
  • 4
  • 31
  • 46

3 Answers3

26

You could use the Text widget:

from tkinter import *

root = Tk()
text = Text(root)
text.pack()
root.mainloop()

Or with scrolling bars using ScrolledText:

from tkinter import *
from tkinter.scrolledtext import ScrolledText

root = Tk()
ScrolledText(root).pack()
root.mainloop()
Kijewski
  • 25,517
  • 12
  • 101
  • 143
timc
  • 2,124
  • 15
  • 13
  • 12
    I *highly* recommend *not* importing everything from Tkinter. IMO you should use `import Tkinter as tk; tk.Tk()...`. It makes your code more self-documenting and immune to problems caused by importing other libraries that have functions with the same name as the Tkinter widgets (for example, ttk and tk both have classes named `Button`) – Bryan Oakley Mar 12 '12 at 11:17
  • 2
    @BryanOakley I completely agree and admit that my answer was done in haste. Thanks for the edit. I haven't updated the code so your comment will stand but am happy to do so if you think it's worthwhile. – timc Mar 12 '12 at 13:06
  • 3
    Is there a way to use a stylable widget to achieve the same result? The `Text` Widget seems to not be available in ttk. – Zelphir Kaltstahl Aug 08 '15 at 23:13
  • @Zephir You can always import both, as such: `from tkinter import *, from tkinter import ttk`, since * doesn't include ttk by default. – mazunki Jan 04 '19 at 18:36
2

Just use Text() widget.

For example:

import tkinter as tk

root = tk.Tk()
text = tk.Text(root)
text.pack()
root.mainloop()

Output:

Output

0

Check out this post. I based it on a tutorial that I found.

It might need some extra work, depending on you requirements, but it's a good start and it is based on TreeView, but allows in-place edits.

You would just need to strip out a few CustomTkinter lines if you want to work in pure Tkinter.

Clive Bostock
  • 150
  • 1
  • 11