0

I am using a Tkinter python 2.6 UI and I am trying trying to use a button to skip though an elememt in a list of commands if a particular command takes too long. Essentially I trying to execute the 'continue' statement from another function. Consider the following:

def executeCommands(commands):
    for cmd in commands:
        sendCommand(cmd)


#arbitrary button class used as an example  
class Button(self)

    #this button executes onSkip() method when clicked
    self.skipBtn = Button('skip', command=self.onSkip)

    def onSkip(self):
        #skip to next iteration of loop that was being iterated prior to skip button execution

How would I get the executeCommands method to stop what its doing and skip to the next cmd when the onSkip method from the Button class is executed?

David
  • 9
  • 1
  • Damn, Python 2.6? You sure your `import time; time.time()` is working properly? – GeeTransit Mar 03 '19 at 22:38
  • 2
    For a button to work while a function runs you will need some kind of threading. Do you have that already? Can you show it to us? – Klaus D. Mar 03 '19 at 22:42
  • The Button is a widget made available by the Tkinter UI plug in. (i.e. import Tkinter) – David Mar 03 '19 at 22:56
  • The code provided is not operational code used, it is provided as an attempt to simply providing a visual reference of the task I am trying to accomplish – David Mar 03 '19 at 22:58
  • @David: *"execute the 'continue' statement from another function"*: Call inside `def onSkip(...` the `continue statement of the other function`. – stovfl Mar 04 '19 at 15:55
  • @stovfl That is what I am trying to do; however I cannot figure out how to do that. Do you have any recommendations? – David Mar 04 '19 at 19:20
  • @David: *"skip though an elememt"*: You mean, **kill** `sendCommand(cmd)`? I assume you have **no access** to the code of `sendCommand(`. Therefore `sendCommand(...` have to be a [`Thread`](https://stackoverflow.com/questions/323972/is-there-any-way-to-kill-a-thread) or [`Process`](https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Process.terminate) – stovfl Mar 04 '19 at 20:34

0 Answers0