This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Tkinter - Unexpected behavior after creating around 10000 widgets
Type: crash Stage: resolved
Components: Tkinter Versions: Python 3.8
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: epaine, gpolo, j.lahav, serhiy.storchaka
Priority: normal Keywords:

Created on 2020-08-25 12:23 by j.lahav, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
ten_k.py j.lahav, 2020-08-25 12:23 code sample
ten_k.tcl epaine, 2020-08-25 13:29
Messages (3)
msg375888 - (view) Author: Jonathan Lahav (j.lahav) Date: 2020-08-25 12:23
Observation:
After creating around 10000 widgets (verified with ttk.Label), no more widgets get created, and sometimes graphical artifacts appear outside the application window.

No error message or exception is raised.

Expected:
Either the limit can be removed (having dynamically created 10000 widgets in data heavy applications is sometimes desired), or at least document and return runtime errors to prevent the weird behavior.

Reproduction:
This is the problematic part:
for _ in range(10000):
    ttk.Label(root, text='problematic')

A full minimal example code is attached, though a better effect can be seen when running the above two lines in the context of a more advanced Tkinter application.
msg375889 - (view) Author: E. Paine (epaine) * Date: 2020-08-25 13:29
I am struggling to reproduce. On Linux the window shows exactly as expected (it does take a while to close, though, which is understandable) and on Windows the window never shows (it gets stuck before the mainloop). This is, however, not a tkinter problem as I get exactly the same result on each platform running the following equivalent Tcl in Wish:

for {set i 0} {$i < 10000} {incr i} {
    ttk::label ".l$i" -text problematic
}
grid [ttk::label .lb -text {now you see me}]

A similar issue was reported in #37673. If you *need* lots of widgets (e.g. a large table) I would suggest lazy loading them instead of trying to render them all at load. Thank you for reporting this issue but it should be closed as third-party.

A note for future: please could you include information about your environment (Python version, Tk patchlevel, OS, etc.) so it is easier for the problem to be narrowed down (again, thank you for reporting this issue).
msg375899 - (view) Author: Jonathan Lahav (j.lahav) Date: 2020-08-25 20:51
Thank you for checking it so quickly, and answering nicely.

I indeed forgot to mention that it happened to me on Windows. Sorry for that.

The issue seems similar to the one you linked. I will try and take this to the TCL community since it impacts our product. Thank you for translating the code to TCL.

If the python community has no interest in trying to push TCL to fix it, this issue can be closed.

Thanks!
History
Date User Action Args
2022-04-11 14:59:35adminsetgithub: 85798
2020-08-26 11:22:15serhiy.storchakasetstatus: open -> closed
resolution: third party
stage: resolved
2020-08-25 20:51:08j.lahavsetmessages: + msg375899
2020-08-25 13:29:34epainesetfiles: + ten_k.tcl
nosy: + epaine
messages: + msg375889

2020-08-25 12:23:41j.lahavcreate