0

I've used tk a fair amount mostly by grabbing bits of code from the web and stitching them in. So I'm sort of familiar, but still confused, even after reading a couple of tutorials. I'm hoping someone will be nice enough to explain what's actually going on.

What I'm trying to do this time is go through a list of cases, and for any which meet the criteria, display the results as we go.

My flow is something like this:

set up tk text box
get a list of items (from an API call)
for item in list:
    make a couple of API calls to get data on the item
    do some processing
    if item meets criteria:
        find item's position in the list of criteria-meeting items (i.e. i'm sorting as I go)
        insert item[details] in text box at the relevant position

So it's really not hard. Left to myself I would probably create the window as a class then refer to it in the main code with a sort of window.update(text, position) function. But I know I need to put mainloop() in there somewhere (where?), and it's at this point that I realise I fundamentally don't understand how tk works, so I know when I write the code it won't work, I won't know what's wrong, and I'll end up stitching together stuff that I find on the web, unless someone is good enough to tell me what's actually going on.

Andrew
  • 67
  • 6
  • Thank you, it might. Does that mean I could have window.update() in my main code, I guess right after the insert item line, and not have mainloop() at all, with the idea that the window gets updated only when it has new data to process? – Andrew Apr 27 '20 at 11:07
  • 1
    Read also to understand [Event-driven_programming](https://en.m.wikipedia.org/wiki/Event-driven_programming). Read through [`[tkinter] event driven programming`](https://stackoverflow.com/search?q=is%3Aanswer+%5Btkinter%5D+event+driven+programming+entry) and [tkinter: how to use after method](https://stackoverflow.com/a/25753719/7414759) – stovfl Apr 27 '20 at 12:05

0 Answers0