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.


    Ui textfield and SQLite DB

    Pythonista
    ui.textfield sqlite
    2
    4
    3137
    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.
    • sara55
      sara55 last edited by ccc

      Hi,
      I would like to get input from ui.textfields and. Insert the data into SQLite DB.
      I have used a button action to read the fields and insert to the DB.Is there a better way of doing it without the button?

      import ui
      import sqlite3
      
      def button_action(sender):
      	#con = sqlite3.connect(":memory:")
      	conn = sqlite3.connect('jubk.db')
      	#con.isolation_level = None
      	c = conn.cursor()
      #	c.execute('''CREATE TABLE emploee_db3 
      #		(id_num text, first text, last text)''')
      	first = first_name_f.text
      	last = last_name_f.text
      	id_num = id_num_f.text
      	print('first name ', first, 'last name ', last, 'id ', id_num)
      	
      	c.execute("INSERT INTO emploee_db3 VALUES (:id_num, :first, :last)", {'id_num': id_num, 'first': first, 'last': last})
      	for row in c.execute('SELECT * FROM emploee_db3'):
      				print(row)
      	conn.commit()	
      		
      v = ui.load_view()
      v.present('sheet')
      
      first_name_f = v['first_f']
      last_name_f = v['last_f']
      id_num_f = v['idnum']
      
      1 Reply Last reply Reply Quote 0
      • brumm
        brumm last edited by

        "TextField.action: A function or method that gets called when text field has finished editing."
        So you could check if all textfields have a valid value, insert them to your db and clear the textfield.text

        def textfield_action(self, textfield):
            # This is called after pressing RETURN
            if ...
                c.execute...
                self.tf_first.text = ''
                ...
        
        

        Btw. this is an example of a own view class.

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

          Thanks, I will try

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

            It works, thank you very much

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