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.
2 (easy) Questions
-
Hey! :)
-
Question: I created a label and a button, i also created an event called "button_tapped", what i want is now that every time someone presses on this Button the Label changes via Label.Text, but he should get the old Value (for example 0) and add the an Amount (for example 2), the Button should show "2" now. :) Sry bad english
-
Question: How am i able to react on an hud.password()? For example to get the Textfields Value?
Thy
-
-
What is
hud.password()
? Did you meanconsole.password_alert()
? -
If you set your password alert in a variable, then you can use that variable for the TextField's text value. Example:
import console myPassword = console.password_alert() print myPassword
This would print out the password that the user inputted.
-
def button_tapped(sender): previousAmount = sender.title # sets previous button's title in a variable. sender.title = previousAmount + 2 # adds 2 to the title, and displays it.
-
To extend on @AtomBombed's answer I would also consider checking that
previousAmount
is stored as an integer or a float otherwise an error will be raised that type Int cannot be added to type str
Iedef button_tapped(sender): try: previousAmount = int(sender.title) except TypeError as e: # This will only make sure that 'sender.title' can be converted to a integer. It is not necessary if the title can always be converted print e previousAmount = 0 sender.title = previousAmount + 2
-
No, its sadly just a "TypeError: coercing to Unicode: need string or buffer, int found
-
sender.title = str(previousAmount + 2)
-
@NRWTV2 , many ways to skin a cat as they say. This is one way. But many variations on this theme.
Most of the code below is just styling the objects. When you weed that out, there is very little being done# coding: utf-8 import ui def btn_action(sender): # sender is the button # could do the below line, maybe not so clear... so will write it out #the_value = int(sender.connected_label.text) lb = sender.connected_label # dynamically created attribute int_val = int(lb.text) the_value = int_val print the_value lb.text = str(the_value + sender.increment_value) f = (0,0,200,200) v = ui.View(frame = f) v.bg_color = 'white' lb = ui.Label(frame = (10,10,100, 32)) lb.text = '1001' btn = ui.Button(frame = (10, lb.height + 30, 80, 32)) btn.title = 'Hit Me' btn.action = btn_action btn.border_width = .5 btn.corner_radius = 3 ''' very important, the 2 next lines of code are referencing attributes that dont exist in a ui.Button. They are created dynamically because you assign a value to them ( i think thats the right jargon) ''' btn.connected_label = lb btn.increment_value = 10 v.add_subview(btn) v.add_subview(lb) v.present('sheet')```
-