I have a program that will count the index length of a highlighted area. I wanted to use tix balloon to show the the result. But in order to use the tix balloon, it required me bind it to the a widget. Instead of binding it to a whole widget, I only want the balloon to show once when a certain event is being called.
Demo of my program (Count start and end index of the highlighted area)

Expected output
The balloon will show the result beside the highlighted area

Code
root.mainloop()from tkinter import *
import tkinter.tix as tkx
def print_count(event):
if text.tag_ranges('sel'):
global s0 , s1
s0 = text.index("sel.first")
s1 = text.index("sel.last")
countstringstart = s0.split('.')[1]
countstringend = s1.split('.')[1]
print(countstringstart)
print(countstringend)
waitshowballon()
root = tkx.Tk()
global text
text = Text(root)
text.bind('<ButtonRelease-1>', print_count)
text.pack()
def waitshowballon():
tooltip = tkx.Balloon(root, initwait=100)
tooltip.bind_widget(text, balloonmsg=s0)
root.mainloop()
Create your own tooltip. tix don't seem to provide position parameter.
Creating your own tooltip is quite simpler than you think. This answer will give you an idea on how to make your own tooltip.
Create a
showfunction that takes the indexes as parameters. Use.bbox(index)to get the position of the index and display the tooltip just above the selected letter.Sample code: