Re: GTK glade SQLite Problem



Have a look at one of my projects. They're in Perl, but the logic flow
is the same:

http://search.cpan.org/~dkasak/Gtk3-Ex-DBI-3.2/lib/Gtk3/Ex/DBI/Form.pm

Briefly, there are issues in your example code. In insert_sqlite() you
need to fetch values back from your builder object. In perl, you'd do
that like:

$builder->get_object( 'some_widget_name' )->get_value

 ... assuming the widget actually has a 'get_value' method. Some
widgets will have other ways of getting at their values. Sorry - I'm
not a huge Python fan. Maybe there are some libraries you can leverage
already. I've actually considered porting my 'form' and 'datasheet'
classes to Python, but ... well ... I'm not a huge Python fan :)

If you're going to push ahead, first implement and test the logic to
insert a record into SQLite, with some hard-coded values. Then
implement the logic to fetch values from your builder object. Then
combine the 2.

Dan

On Mon, Oct 24, 2016 at 4:34 PM, Sangram Kakade
<sangramrajekakade gmail com> wrote:
Hello Everyone,

I am Newbie in Python and i want some help
I already created DB and in glade two Text Entry Box and one button
and i want when i put some value in text entry it must be stored in db

here is my code:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import sqlite3
import sys


class Handler:

    def insert_sqlite():
        connection = sqlite3.connect('mydatabase')
        cursor = connection.cursor()
        sql ="INSERT INTO person_info (name,lastnm) VALUES ('%s','%s')"
        cursor.execute(sql)
        data = cursor.fetchall()

        for d in data:
            print(d)


        connection.commit()
        connection.close


    def display_details():
        connection = sqlite3.connect('mydatabase')
        cursor = connection.cursor()
        sql = "SELECT * FROM person_info "
        cursor.execute(sql)
        data = cursor.fetchall()

        for d in data:
            print(d)

        connection.commit()
        connection.close


builder = Gtk.Builder()
builder.add_from_file("cool.glade")
builder.connect_signals(Handler())
window = builder.get_object("window1")
window.show_all()

Gtk.main()



I also set signal in glade
clicked signal( insert_sqlite)
on save button

but data is not save in Database
Please Help me guys
--
Thanks & Regards,
Sangram Kakade <http://www.sangramkakade.com>
Python/Django Developer
Mob.No. 9975159162 / 8796535503
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]