Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that you're calling <code>hello(i)</code> at the time of construction of the <code>Radiobutton</code>, not storing something to be called later:</p> <pre><code> c.append(Radiobutton(frameData, text=InputBox.get(i), variable=inputVar, value = i, background="grey", command= hello(i))) </code></pre> <p>Since <code>hello</code> returns <code>None</code>, you're effectively storing <code>command=None</code>.</p> <p>You need to store a callable here, like <code>hello</code> itself, (or a <code>lambda</code> or <code>partial</code>, or whatever), not the result of calling it.</p> <p>For example:</p> <pre><code> c.append(Radiobutton(frameData, text=InputBox.get(i), variable=inputVar, value = i, background="grey", command=functools.partial(hello, i))) </code></pre> <p>Since you asked in the comments: Note that I used <code>partial</code> rather than <code>lambda</code>, because I want to bind in the value of <code>i</code>, not close over the variable <code>i</code>. Otherwise, you'd end up with, e.g., 5 radio buttons all bound to the same variable <code>i</code> with the value <code>4</code>. There are other ways around this—use an explicit factory, do <code>lambda x=i: hello(x)</code> instead of <code>lambda: hello(i)</code>, etc. To me, <code>partial</code> seems like the clearest and most explicit, but your mileage may vary. Anyway, there are dozens of questions on SO about this, but the answer to <a href="https://stackoverflow.com/questions/938429/scope-of-python-lambda-functions-and-their-parameters">Scope of python lambda functions and their parameters</a> seems particularly clear.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload