1 # A CallTip window class for Tkinter/IDLE.
2 # After ToolTip.py, which uses ideas gleaned from PySol
4 # Used by the CallTips IDLE extension.
10 def __init__(self
, widget
):
16 def showtip(self
, text
):
18 if self
.tipwindow
or not self
.text
:
20 self
.widget
.see("insert")
21 x
, y
, cx
, cy
= self
.widget
.bbox("insert")
22 x
= x
+ self
.widget
.winfo_rootx() + 2
23 y
= y
+ cy
+ self
.widget
.winfo_rooty()
24 self
.tipwindow
= tw
= Toplevel(self
.widget
)
25 tw
.wm_overrideredirect(1)
26 tw
.wm_geometry("+%d+%d" % (x
, y
))
27 label
= Label(tw
, text
=self
.text
, justify
=LEFT
,
28 background
="#ffffe0", relief
=SOLID
, borderwidth
=1,
29 font
= self
.widget
['font'])
39 ###############################
43 class container
: # Conceptually an editor_window
46 text
= self
.text
= Text(root
)
47 text
.pack(side
=LEFT
, fill
=BOTH
, expand
=1)
48 text
.insert("insert", "string.split")
50 self
.calltip
= CallTip(text
)
52 text
.event_add("<<calltip-show>>", "(")
53 text
.event_add("<<calltip-hide>>", ")")
54 text
.bind("<<calltip-show>>", self
.calltip_show
)
55 text
.bind("<<calltip-hide>>", self
.calltip_hide
)
58 # root.mainloop() # not in idle
60 def calltip_show(self
, event
):
61 self
.calltip
.showtip("Hello world")
63 def calltip_hide(self
, event
):
64 self
.calltip
.hidetip()
70 if __name__
=='__main__':