NationWidePants
NationWidePants

Reputation: 447

tkinter winfo_children dynamic association

I'm trying to figure out if an Entry is blank, but instead it skips over it in my code and appends the next Entry object, if the Entry has data, to the array. When I try to identify the object it gives a reference, but not the type of object (i.e. .140594722293880....). I've tried if i.get() != "": and None, is there a way to identify an empty Entry?

import os,sys
import Tkinter as tkinter
import ttk
class CLASSTHING():
   def __init__(self):
        top = tkinter.Tk()
        top.geometry('1200x150')
        top.title('')
        master = ttk.Frame(top)
        n = ttk.Notebook(master)
        f1 = ttk.Frame(n)
        for x in range(0,len(labelstr) -1):
            tkinter.Label(f1, text=labelstr[x], width=len(labelstr[x])).grid(row=x,column=0)
            tkinter.Entry(f1, width=100).grid(row=x,column=1)
        submit = tkinter.Button(top,text="submit",command= lambda: 
self.enterData([f1])
        submit.place(x=1152,y=25)    
        n.add(f1,text='1')
        top.mainloop()

    def enterData(self,Frame):
        ary = []
        for a in frame:
            for i in a.winfo_children():
                ary.append(i.get())

My coding is compatible with both Python 3 and 2. If you have a suggestion, please give whichever you know best.

Upvotes: 0

Views: 800

Answers (1)

patthoyts
patthoyts

Reputation: 33203

You can use the winfo_class method to get the class for any Tk or Ttk widget. For Entry widgets the class is "Entry", a ttk entry widget would be "TEntry". This is application specific though as the programmer may assign a different class to a widget to associate a different visual style in ttk or different options in standard Tk.

Upvotes: 2

Related Questions