Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.mb-net.net!open-news-network.org!.POSTED!not-for-mail From: Bart Kastermans Newsgroups: comp.lang.python Subject: Tkinter label height to fit content Date: Sat, 03 Sep 2011 16:15:18 -0600 Organization: MB-NET.NET for Open-News-Network e.V. Lines: 22 Message-ID: <87mxelgtmx.fsf@gmail.com> NNTP-Posting-Host: kasterma.colorado.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: gwaiyur.mb-net.net 1315088122 19219 128.138.150.65 (3 Sep 2011 22:15:22 GMT) X-Complaints-To: abuse@open-news-network.org NNTP-Posting-Date: Sat, 3 Sep 2011 22:15:22 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) X-User-ID: U2FsdGVkX1/lLkWrh6vC1dTVrpfhr/+f6RKkJ3TDM2Dm0I/v+5Qg2P6qMIMeT6BO Cancel-Lock: sha1:WzVcga8atrlKJtt7ZGNtn5lf3tE= sha1:KwgapRLboqzqe/Tbn9dQhtzhGtM= Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12725 I have a label into which I am going to put content of different sizes. I would like to know how high I need to make the label so that I can size the window so it can stay the same for the different content sizes. I have a strategy, but it seems more complicated then it should be. I want to set a label to a given width and wraplength: l = Label(root) l['width'] = 30 l['wraplength'] = 244 l['text'] = "testing this" Now I want to query the label to find how many lines are used. l['height'] stays at 0, so the best I have been able to come up with is to use l.winfo_height() and convert the height given in pixels to the number of lines used. Nothing in dir(l) seems to give me the information directly, but this strategy is fragile to font changes and other changes. Any suggestions?