Question

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.

Was it helpful?

Solution

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).

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top