Pattern Matching Tkinter child widgets (winfo_children) to determine type (Python)
Question: I'm trying to automatically clear all Entry widgets in a parent widget.

    
    
    import Tkinter
    import re
    root=Tkinter.Tk()
    
    E1=Tkinter.Entry(root)
    E1.pack()
    
    E2=Tkinter.Entry(root)
    E2.pack()
    
    L1=Tkinter.Label(root,text='Label1')
    L1.pack()
    

I'm running into 3 problems

  1. While I can find out the children widget type, I can't seem to be able to use it in a pattern match. Printing out the wlist[0] below is different from the shell output ? 

Eg:

    
    
    >> wlist=root.winfo_children()
    >> wlist
    [<Tkinter.Entry instance at 0x00000000151911C8>,
     <Tkinter.Entry instance at 0x00000000151BAD88>,
     <Tkinter.Label instance at 0x00000000151B29C8>]
    
    >> wlist[0]    # shell output
    <Tkinter.Entry instance at 0x00000000151911C8>
    
    >> print wlist[0]   # print output here is different vs shell output above
    .353964488L
    

  2. I think due to the differences between the print output & shell output above, my pattern match can't work?

Eg

    
    
    >> re.search(r'Entry',wlist[0])
        << No output >>
    

  3. Assuming one is able to detemine via pattern match that a child widget is indeed an Entry widget, how would you get the widget object itself to perform a delete method call?

Eg:

    
    
    ## Assuming I have a function to to clear the entry
    ## How would I pass the object from the pattern match in #2 to this function?
    def clear_entry(objEntry):
        objEntry.delete(0,Tkinter.END)
    


Answer: Normally you store them in a list or some container.

    
    
    entry_list=[E1, E2]
    
    def clear_entry():
        for id in entry_list:
            id.delete(0,Tkinter.END)
    

