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.
Syntax Error add_subview line 23
My script is presenting a syntax error in the line 23. What I want is to show a main view as an introduction of the app I am creating. I am a beginner so appreciate any help. As you can see there are a lot # for comments because is the way I am experimenting. Thanks
The error is in this :
import ui import console import sqlite3 conn = sqlite3.connect(":memory:") c = conn.cursor() # Create table c.execute('''CREATE TABLE IF NOT EXISTS logindata (date_login, user_name, pwd_user)''') # Insert a row of data #c.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14)") # Save (commit) the changes conn.commit() # We can also close the connection if we are done with it. # Just be sure any changes have been committed or they will be lost. #global icontador vanimation=ui.View(frame = (0,0,800,800), bg_color = '#34d1bd', name = 'Habitfun Init') labelmain = ui.Label(alignment=ui.ALIGN_CENTER,bg_color='#fafafa',border_color='black',border_width=1,frame=(100, 150, 300, 40),name='labelmain',text='WELCOME TO HABITfun, text_color = '#0d60fd') vanimation.add_subview(labelmain) vanimation.present('sheet') def button1_tapped(sender): sender.superview.close() def button2_tapped(sender): alert_result = console.alert('Title', 'HOLA MARIANA, BUENOS DIAS', 'Button 1', 'Button 2') button1 = ui.Button(title = 'SALIR', alignment=ui.ALIGN_CENTER, bg_color = '#ff1a55', font_color = 'black') button1.frame = (100,400,100,50) button1.tint_color = 'black' button1.border_width = 1 button1.action = button1_tapped button2 = ui.Button(title = 'ACEPTAR', alignment=ui.ALIGN_CENTER, bg_color = '#ff1a55', font_color = 'black') button2.frame = (300,400,100,50) button2.tint_color = 'black' button2.border_width = 1 button2.action = button2_tapped label1 = ui.Label(alignment=ui.ALIGN_CENTER,bg_color='#fafafa',border_color='black',border_width=1,frame=(100, 150, 300, 40),name='User',text='User Name', text_color = '#0d60fd') label2 = ui.Label(alignment=ui.ALIGN_CENTER,bg_color='#fafafa',border_color='black',border_width=1,frame=(100, 250, 300, 40),name='Password',text='Password', text_color = '#0d60fd') t1=ui.TextField(frame=(100,200,300,40)) t2=ui.TextField(frame=(100,300,300,40)) t1.begin_editing() v=ui.View(name='Habitfun', bg_color='#545fd1',frame=(0,0,500,500)) v.add_subview(label1) v.add_subview(label2) v.add_subview(button1) v.add_subview(button2) v.add_subview(t1) v.add_subview(t2) def tfaction(textfield): '''when you change the textfield, and press return, this metjod is called''' print('textfield changed:', textfield.text ) t1.action=tfaction v.present('sheet')
@sendog3c missing quote, thus "end )" is commented, thus no "end )", thus next line is part of the statement, etc... 😀
labelmain = ui.Label(alignment=ui.ALIGN_CENTER,bg_color='#fafafa',border_color='black',border_width=1,frame=(100, 150, 300, 40),name='labelmain',text='WELCOME TO HABITfun', text_color = '#0d60fd')
Color of ) should show you where is the error
thank you. You are a helper 😌😌
@sendog3c That's not what my wife says 😂
ccc last edited by
@cvp. You should convince your wife to do https://en.m.wikipedia.org/wiki/Pair_programming with you.
Can make you a theory question ?
@ccc My wife is an artist and she hates computers...
jejeje nice jokes
@sendog3c My "?" was about your theory question
My question are basically: how do I have to structure my code; by example: the entire code in only one *.py file or should I divide it in parts; and if it better in parts how to do that?
mikael last edited by
@sendog3c, see one big comprehensive answer here.
For my Pythonista coding and fun projects, I mostly stay in one file until:
- It is too long to keep scrolling up and down on the phone
- Or I need to develop in two locations at once, in which case it is more convenient to jump between two files = tabs
- I have alternative components that you pick from when importing, like different storage backends
- Or the project gets really big and splitting into logical files and folders is necessary just to find things
Thank you CVP & Mikael. I am going to read the article prior to continue. But a last question for instances:
How do I call a .py from another .py when running your program?
@sendog3c If you need to call some def's, easiest way = import, like you do for standard modules:
p1.py ===== def my1(): ........ p2.py ===== import p1 p1.my1()