<s> from Tkinter import * <EOL> class ToolTipBase : <EOL> def __init__ ( self , button ) : <EOL> self . button = button <EOL> self . tipwindow = None <EOL> self . id = None <EOL> self . x = self . y = <NUM_LIT:0> <EOL> self . _id1 = self . button . bind ( "<STR_LIT>" , self . enter ) <EOL> self . _id2 = self . button . bind ( "<STR_LIT>" , self . leave ) <EOL> self . _id3 = self . button . bind ( "<STR_LIT>" , self . leave ) <EOL> def enter ( self , event = None ) : <EOL> self . schedule ( ) <EOL> def leave ( self , event = None ) : <EOL> self . unschedule ( ) <EOL> self . hidetip ( ) <EOL> def schedule ( self ) : <EOL> self . unschedule ( ) <EOL> self . id = self . button . after ( <NUM_LIT> , self . showtip ) <EOL> def unschedule ( self ) : <EOL> id = self . id <EOL> self . id = None <EOL> if id : <EOL> self . button . after_cancel ( id ) <EOL> def showtip ( self ) : <EOL> if self . tipwindow : <EOL> return <EOL> x = self . button . winfo_rootx ( ) + <NUM_LIT:20> <EOL> y = self . button . winfo_rooty ( ) + self . button . winfo_height ( ) + <NUM_LIT:1> <EOL> self . tipwindow = tw = Toplevel ( self . button ) <EOL> tw . wm_overrideredirect ( <NUM_LIT:1> ) <EOL> tw . wm_geometry ( "<STR_LIT>" % ( x , y ) ) <EOL> self . showcontents ( ) <EOL> def showcontents ( self , text = "<STR_LIT>" ) : <EOL> label = Label ( self . tipwindow , text = text , justify = LEFT , <EOL> background = "<STR_LIT>" , relief = SOLID , borderwidth = <NUM_LIT:1> ) <EOL> label . pack ( ) <EOL> def hidetip ( self ) : <EOL> tw = self . tipwindow <EOL> self . tipwindow = None <EOL> if tw : <EOL> tw . destroy ( ) <EOL> class ToolTip ( ToolTipBase ) : <EOL> def __init__ ( self , button , text ) : <EOL> ToolTipBase . __init__ ( self , button ) <EOL> self . text = text <EOL> def showcontents ( self ) : <EOL> ToolTipBase . showcontents ( self , self . text ) <EOL> class ListboxToolTip ( ToolTipBase ) : <EOL> def __init__ ( self , button , items ) : <EOL> ToolTipBase . __init__ ( self , button ) <EOL> self . items = items <EOL> def showcontents ( self ) : <EOL> listbox = Listbox ( self . tipwindow , background = "<STR_LIT>" ) <EOL> listbox . pack ( ) <EOL> for item in self . items : <EOL> listbox . insert ( END , item ) <EOL> def _tooltip ( parent ) : <EOL> root = Tk ( ) <EOL> root . title ( "<STR_LIT>" ) <EOL> width , height , x , y = list ( map ( int , re . split ( '<STR_LIT>' , parent . geometry ( ) ) ) ) <EOL> root . geometry ( "<STR_LIT>" % ( x , y + <NUM_LIT> ) ) <EOL> label = Label ( root , text = "<STR_LIT>" ) <EOL> label . pack ( ) <EOL> button1 = Button ( root , text = "<STR_LIT>" ) <EOL> button2 = Button ( root , text = "<STR_LIT>" ) <EOL> button1 . pack ( ) <EOL> button2 . pack ( ) <EOL> ToolTip ( button1 , "<STR_LIT>" ) <EOL> ListboxToolTip ( button2 , [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> root . mainloop ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from idlelib . idle_test . htest import run <EOL> run ( _tooltip ) </s>
