<s> import Tkinter as tk <EOL> import ttk <EOL> class ToolButton ( ttk . Button ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , parent , imagedata = None , tooltip = "<STR_LIT>" , text = None , command = None , width = <NUM_LIT:5> , compound = "<STR_LIT>" ) : <EOL> if imagedata is None : <EOL> self . _normal_image = None <EOL> else : <EOL> self . _normal_image = tk . PhotoImage ( data = imagedata ) <EOL> self . tooltip = tooltip <EOL> ttk . Button . __init__ ( self , parent , style = "<STR_LIT>" , image = self . _normal_image , <EOL> command = command , takefocus = False ) <EOL> if text is not None : <EOL> self . configure ( text = text , compound = compound , width = width ) <EOL> self . bind ( "<STR_LIT>" , self . _on_show_tip ) <EOL> self . bind ( "<STR_LIT>" , self . _on_hide_tip ) <EOL> self . tip = tk . Toplevel ( self , borderwidth = <NUM_LIT:1> , relief = "<STR_LIT>" ) <EOL> self . tip . wm_overrideredirect ( True ) <EOL> tiplabel = tk . Label ( self . tip , text = tooltip , background = "<STR_LIT>" ) <EOL> tiplabel . pack ( side = "<STR_LIT>" , fill = "<STR_LIT>" , expand = True ) <EOL> self . _job = None <EOL> self . tip . wm_withdraw ( ) <EOL> if self . tip . tk . call ( "<STR_LIT>" , "<STR_LIT>" ) == '<STR_LIT>' : <EOL> self . tip . tk . call ( "<STR_LIT>" , "<STR_LIT>" , self . tip . _w , "<STR_LIT>" , "<STR_LIT:none>" ) <EOL> def _on_show_tip ( self , event ) : <EOL> self . _cancel ( ) <EOL> self . _job = self . after ( <NUM_LIT> , self . _show_tip ) <EOL> def _on_hide_tip ( self , event ) : <EOL> self . _cancel ( ) <EOL> self . tip . wm_withdraw ( ) <EOL> def _show_tip ( self ) : <EOL> x0 = self . winfo_rootx ( ) <EOL> y0 = self . winfo_rooty ( ) <EOL> x = x0 <EOL> y = y0 + self . tip . winfo_reqheight ( ) + <NUM_LIT:12> <EOL> geometry = "<STR_LIT>" % ( x , y ) <EOL> self . tip . wm_geometry ( geometry ) <EOL> self . tip . deiconify ( ) <EOL> def _cancel ( self ) : <EOL> if self . _job is not None : <EOL> self . after_cancel ( self . _job ) <EOL> self . _job = None </s>
