tags:

views:

21

answers:

1

I have a label sitting on a frame which is updated periodically to show the status of the application. Periodically, the name of the item being processed will not fit into the window, and with the way I currently have the label configured the window expands to accomidate the label.

Ideally, I'd like way to smartly truncate the text on the label (and then expand if someone expands the window). Is there an easy way to accomplish this?

Practically speaking, how can I just stop the window to expanding based on changes to text in the label?

Edit:

This is an aproximation of the code I'm working on that is not exhibiting the desired behavior (there is a link at the bottom to the actual code file):

r = tk.Tk()               
statusFrame = tk.Frame(r, relief=tk.SUNKEN, borderwidth=2)
statusFrame.pack(anchor=tk.SW, fill=tk.X, side=tk.BOTTOM)
statusVar = tk.StringVar()       
statusVar.set("String")                   
tk.Label(statusFrame, textvariable=statusVar).pack(side=tk.LEFT)
statusVar.set("this is a long text, window size should remain the same")

Actual code available here.

A: 

The answer depends very much on the way you currently have configured the widget.

For example, I can get the desired functionality as such:

>>> import Tkinter as tk
>>> r=tk.Tk()
>>> r.title('hello')
''
>>> l= tk.Label(r, name='lbl', width=20, text='reduce the window width')
>>> l.pack(fill=tk.BOTH) # or tk.X, depends; check interactive resizing now
>>> l['text']= "This is a long text, window size should remain the same"

Tell us what you do in your code for a more precise (appropriate for your code) answer.

ΤΖΩΤΖΙΟΥ
I had to fiddle a little with your example, but the settings got it to work. Thanks!
Mark Roddy