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.
Struggling to UI a grid of fields
-
Hello all, totally new to Python and Pythonista although I do have experience of AppleScript.
First up kudos to Ole, fantastic app.
Second up is my head scratcher. I'm trying to create a UI with a grid of uniquely identifiable text fields. I don't think I can use a PYUI as I need a running digital clock on the screen at the same time, so I figured I would need to create the UI screen in the code.
My code to make the first column makes a text box for each iteration through the loop but only the last one displays. What can I add/change to get the earlier ones to display?
Thanks, Alan
import ui
def fieldEdited(sender):
t=view[fieldName].text
print tfor loop in range(1,11):
fieldName='field' + str(loop)view = ui.View() view.background_color = 'white' field = ui.TextField() field.name='field'+str(loop) field.text= fieldName field.center = (70,(90+loop*30)) field.height=27 field.width=82 field.action = fieldEdited
view.add_subview(field)
view.present(style='full_screen',hide_title_bar='True')
-
Sorry that was untidy, I'll try again
def fieldEdited(sender): t=view[fieldName].text print t for loop in range(1,11): #print loop fieldName='field' + str(loop) view = ui.View() view.background_color = 'white' field = ui.TextField() print fieldName field.name='field'+str(loop) field.text= fieldName field.center = (70,(90+loop*30)) field.height=27 field.width=82 field.action = fieldEdited view.add_subview(field) view.present(style='full_screen',hide_title_bar='True')````
-
Oh! just someone shoot me.
-
when you post code, prefix and postfix it all with three backticks. If your prefix has the word python immediately after it, you color coding. Much easier to read.
-
def fieldEdited(sender): t=view[fieldName].text print t for loop in range(1,11): #print loop fieldName='field' + str(loop) view = ui.View() view.background_color = 'white' field = ui.TextField() print fieldName field.name='field'+str(loop) field.text= fieldName field.center = (70,(90+loop*30)) field.height=27 field.width=82 field.action = fieldEdited view.add_subview(field) view.present(style='full_screen',hide_title_bar='True')```
-
Please polymerchm could you save me?!
-
In your action,
sender.name
returns the name of the textview you have edited. -
put the first three back ticks on their own line immediately followed by
python
. After all the code, on its own line, three more backticks -
Sorry it just displays very badly, it does not like my Apple Mac text.
-
blank line three backticks python<return!!!> your code three backticks
You can edit any of your existing posts by clicking
edit
at the upperright of the post. -
import ui def fieldEdited(sender): t=view[fieldName].text print t for loop in range(1,11): #print loop fieldName='field' + str(loop) view = ui.View() view.background_color = 'white' field = ui.TextField() print fieldName field.name='field'+str(loop) field.text= fieldName field.center = (70,(90+loop*30)) field.height=27 field.width=82 field.action = fieldEdited view.add_subview(field) view.present(style='full_screen',hide_title_bar='True')
-
Thank you ccc, who would have thought I could make such a mess of it?
Now can anybody solve my original problem, it's a long way back.
-
import ui def fieldEdited(sender): t=sender.text # note change print t view = ui.View() view.background_color = 'white' for loop in range(1,11): #print loop fieldName ='field' + str(loop) field = ui.TextField() field.name = fieldName field.text= 'type something' field.center = (70,(90+loop*30)) field.height=27 field.width=82 field.action = fieldEdited view.add_subview(field) view.present(style='full_screen',hide_title_bar='True')
-
Wow, thanks. A simple as that, and no doubt after a lot of experience on your part. Thanks.