0

so for example

window = Tk()

lbl = Label(text='abc')
lbl.place(x=1, y=1)

lbl2 = Label(text='ABC')
lbl2.place(x=2, y=2)

numOfWidgets = window.amount
print(str(numOfWidgets))

>>> 2

Does anyone know if there is a way to do this?

  • When you say "call the amount", did you mean "_count_ the amount"? – Bryan Oakley Jan 20 '20 at 19:11
  • Read [Basic Widget Methods - Widget.winfo_children-method](http://effbot.org/tkinterbook/widget.htm#Tkinter.Widget.winfo_children-method) – stovfl Jan 20 '20 at 19:47
  • Does this answer your question? [Getting every child widget of a Tkinter window](https://stackoverflow.com/questions/7290071/getting-every-child-widget-of-a-tkinter-window) – stovfl Jan 20 '20 at 19:56

1 Answers1

0

The method winfo_children will return the children of a given window. You can use that information to iterate through all of the widgets if you need a count of all widgets in an application.

In your case, len(window.winfo_children()) will return 2.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685