0

I'm using a TixBalloon to generate tooltips in a GUI, some of the Entry widgets I would like the tooltip or status message to be the text of the StringVar() variable. So the code would look something like:

from Tkinter import *
from Tix import *
root = Tk()
status = Label(root, height = 3, width=30, bd=1,bg='yellow',wraplength = 210)
status.grid(row = 0,column = 0,pady = 10)
bal = Balloon(root,statusbar = status)
frame_1 = Frame(root,relief=RIDGE,bd = 2)
frame_1.grid(row=1,column = 0)
Angles = [StringVar(),StringVar()]
Angles[0].set('0')
Angles[1].set('1')

#Incomming
label_in = Label(frame_1,text = "TH_in")
label_in.grid(row = 0,column = 0)

entry_in = Entry(frame_1, width = 20, textvariable = Angles[0])
entry_in.grid(row = 0,column = 1)

#Outgoing
label_out = Label(frame_1,text = "TH_out")
label_out.grid(row = 1,column = 0)

entry_out = Entry(frame_1, width = 20, textvariable = Angles[1])
entry_out.grid(row=1,column=1)

#tool tip / status bar
bal.bind_widget(label_in,balloonmsg='Incidence Angle',statusmsg = Angles[0].get())
bal.bind_widget(label_out,balloonmsg='Detector Angle',statusmsg = Angles[1].get())
root.mainloop()

However this will only show the original value of "Angles[0]" and "Angles[1]" in the status box, and not update it when the text in the entry boxes are changed.

David Duncan
  • 81
  • 1
  • 11

2 Answers2

2

You can use StringVar.trace to bind a callback which will be called whenever the StringVar is changed. Presumably, you could use that callback to change the statusmsg in bal (although, I don't know anything about Tix and Balloon, so I could be wrong).

mgilson
  • 300,191
  • 65
  • 633
  • 696
  • That could well work - I know that you can't use the trace on the actual status message itself (well you can trace it, but the call back fails to effect the actual status message), but it may be possible to get it to alter the bound message.... I shall go and try. – David Duncan Nov 01 '12 at 15:28
  • It worked, more or less, sadly it doesn't force the balloon to update as you type (you have to move the mouse away and back again), but I think that is a limitation of Tix.Balloon more than anything else. – David Duncan Nov 01 '12 at 15:39
  • You could use something like `bal.subwidget('message')["text"] =` in your callback to update the ballon label instantly (however, you would need some tests to find which tooltip is active). – FabienAndre Nov 01 '12 at 19:56
1

The balloon Tix widget is a mega-widget composed of actual Tkinter/Tix widgets.

You can retrieve the Label message through bal.subwidget('message'), thus you can share the variable between the Entry and the Balloon's Label.

bal.subwidget('message')["textvariable"] = Angles[0]

However, you will need a Balloon instance for each entry/tooltip pair since the message label is shared between all tooltips of a balloon instance.

FabienAndre
  • 4,514
  • 25
  • 38