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.
Can you assign a button input to a variable
-
Im having trouble trying to figure out how to assign a button press to a variable and at first i tried this code
def button_tapped(sender):
'@type sender: ui.Button'a = sender.title
But it obviously did not work
Please help -
@NewbieCoder If you want to store the title of the tapped button in a variable:
import ui v = ui.View() v.frame = (0,0,400,400) v.name = 'test' b = ui.Button() b.title = 'My Title' b.background_color = 'white' b.border_color = 'blue' b.border_width = 1 b.corner_radius = 5 b.frame = (10,10,100,32) a = '' def tap(sender): a = sender.title print(a) b.action = tap v.add_subview(b) v.present('sheet')
-
@NewbieCoder A great answer has been provided by @cvp but I have a different question... Where does the syntax '@type sender: ui.Button' come from? I have not seen that before.
Python 3’s builtin function annotation syntax would be something like def tap(sender: ui.Button) -> None:
-
-
Its just the prerson that tought me
-
Wikipedia says: “The project Epydoc is inactive since February 2009.”.
So, time to drop Epydoc and learn Python’s builtin type annotations... http://www.mypy-lang.org
-
Why you bully me)))
-
@ccc i set my phones date to Декабрь 2008)))))))))))
-
I have no intention to bully you. Only trying to help. Python has a builtin set of capabilities (help(), pydoc, inspect, typing) that will help generate epydoc-like documentation of your code as well as do mypy type checking to find errors. The code that you write will be more future proof and readable by others if it follows the standard.