omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    2
    3
    1500
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • BryanPatrick
      BryanPatrick last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • dgelessus
        dgelessus last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • BryanPatrick
          BryanPatrick last edited by

          Thank you very much!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors