Tkinter label height to fit content

rantingrick rantingrick at gmail.com
Tue Sep 6 23:23:50 CEST 2011


Hmm, i can replace all that code with this...

#
# Easy_as.py
#
import Tkinter as tk
from ScrolledText import ScrolledText
import tkFont
import random
# Create some puesdo data.
data = [
    '{0}.{1}'.format(x, 'blah'*random.randint(4, 50))
    for x in range(100)
    ]
##print data
# Create the main window and a scrolled text widget.
root = tk.Tk()
font = tkFont.Font(family='times', size=13)
textbox = ScrolledText(
    root,
    width=60,
    height=20,
    font=('Times', 10),
    wrap=tk.WORD,
    )
textbox.pack(
    fill=tk.BOTH,
    expand=True,
    padx=5,
    pady=5,
    )
textbox.insert(1.0, '\n\n'.join(data))
# Start the event loop.
root.mainloop()
#
# End
#



More information about the Python-list mailing list