Passing variables with continuous functions?
<p>I am using a function to read an analog value from a joystick and update the label on the tkinter screen. This works well but I also want to use that value outside the function to perform if statements with other returned values. Here is what I have so far:</p>

<pre><code>def joystick():
    global joystick_adc
    joystickRead = readadc(joystick_adc, SPICLK, SPIMOSI, SPIMISO, SPICS)
    joystickValue = joystickRead
    joy_val.config(text=joystickRead)
    joy_val.after(1000, joystick)
    return joystickValue
</code></pre>

<p>After it is returned I am assigning it to a variable using:</p>

<pre><code>joystickVal = joystick()
</code></pre>

<p>But it only returns the value once and not continuously like I had hoped. Is there something I am doing wrong here??</p>

<p>If you <em>really</em> need such architecture, you could do it like this:</p>

<pre><code>def joystick(adc):
    global joystickVal
    joystickVal = readadc(adc, SPICLK, SPIMOSI, SPIMISO, SPICS)
    joy_val.config(text=joystickVal)
    joy_val.after(1000, joystick, adc)

joystick(joystick_adc)  # to start
# Also this wouldn't stop, so you'd better coding it in class with shared
# attribute, used to indicate condition
</code></pre>

<p>But you'd better avoiding such patterns, cause it brings strong coupling. Generally, function should be as independent, as possible</p>

<p>See how it's properly done in ThreadDispatcher <a href="https://gist.github.com/thodnev/d2c70d1034d1b8547fa8edf1c297b859" rel="nofollow">here</a></p>

<p><strong>UPD:</strong> (part of reply to your comment)
for simulating readadc:</p>

<pre><code>def sim(string):
    parts = string.splitlines()
    def callback(*args, **kwargs):
        if parts:
            cur = parts.pop(0)
            return cur
        return 'Empty'
    return callback

sim_adc = sim('Firs\nsecond\nthird\netc...')  # run func with this
</code></pre>

python python-3.x tkinter