2
$\begingroup$

This is probably a silly question, but I've spent all day trying to figure it out and I can't. Below is the code.

Button[
 Dynamic[
  x,
  Initialization :> {x = 0},
  TrackedSymbols :> {x}
  ],
 Table[
  Pause[0.1]; x++,
  {i, 1, 10}
  ]
 ]

When I press the button, the button label jumps from 0 to 10. What I want it to do is show all the values from 0 to 10 (i.e. dynamically update the label every time the value of x changes).

Gabriel

$\endgroup$
2
  • 2
    $\begingroup$ does Button[Dynamic[x], x = 0; Table[Pause[0.1]; x++, {i, 1, 10}], Method -> "Queued"] give what you need? $\endgroup$
    – kglr
    Commented Oct 24, 2019 at 21:28
  • $\begingroup$ yes >_<. thank you! $\endgroup$
    – user12572
    Commented Oct 24, 2019 at 21:31

1 Answer 1

5
$\begingroup$

Use the option Method -> "Queued":

Button[Dynamic[x], 
  x = 0; Table[Pause[0.1]; x++, {i, 1, 10}], Method -> "Queued"]

Button >> Details and options

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.