Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Calculator - predefined number
-
Is there anyone who could help me modify the original calculator example so that you can pass an argument to it from url to predefine the first number for an equation?
-
This can be done relatively easily. At the top of the script, add
import sys
to be able to access the runtime/URL arguments. Then add the following code at the bottom:if len(sys.argv) > 1: v['label1'].text = sys.argv[1]
Basically it checks if there are any runtime arguments (argument 0 is always the script file name) and if there are, it uses the first argument as the display text. Since the calculator pulls the values directly from the text label and doesn't use any other internal variables to store the equation, no other changes are necessary. You can even pass an entire equation, as long as it doesn't contain any spaces.
-
Thank you very much!