in reply to Re^2: How to display Tk window without waiting for user input
in thread How to display Tk window without waiting for user input
The issue is that within the call to check_for_status(); is a webpage scrape; there is no way to have the webpage "push" the status changes to me; I have to determine that myself. For that reason a while (1) loop seems necessary.
Well I certainly hope that whoever is operating the webpage doesn't mind you polling the page that often, and that you're not voilating any TOS. You should definitely add a delay in there so that you're not hitting the webserver constantly.
If this is a Tk GUI then you will need the MainLoop;, and everything needs to happen in there, and kcott's comment that you're on the wrong track by writing your own loop is correct. This means you need to use Tk's functionalities to achieve your "loop", which is usually done by setting a timer to go off in the future, which will then run a callback inside of the main loop, and the callback then starts a new timer. Though I am far from a Tk expert, Tk::after as suggested by kcott seems to be a way to achieve this (Update: tybalt89 and kcott have since posted examples). Either that, or spawn a separate thread/process, though then you've got the complication of two processes needing to be managed and needing to communicate.
Of course, it's a different story if the only thing your code is doing is sending notifications, then most modern window managers have built-in notifications that you can use. For example, on Ubuntu, there's notify-send, which exits immediately and therefore wouldn't block your script (see Calling External Commands More Safely).
|
|---|