我正在使用 TixBalloon 在 GUI 中生成工具提示,一些 Entry 小部件我希望工具提示或状态消息成为 StringVar() 变量的文本。所以代码看起来像:
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()
但是,这只会在状态框中显示“Angles[0]”和“Angles[1]”的原始值,而不会在输入框中的文本更改时更新它。