Yazeka
Arama sonuçlarına göre oluşturuldu
Kivy ile SQLite kullanmak için aşağıdaki adımlar izlenebilir:
- Veritabanını bağlama 3.
sqlite3.connect()
fonksiyonu ile veritabanı bağlanır 3. - Sorgu çalıştırma 3.
cursor.execute()
fonksiyonu ile SQL sorguları çalıştırılır 3. - Kayıt ekleme 3.
cursor.execute()
fonksiyonu ileINSERT INTO
komutu kullanılarak kayıt eklenir 3. - Kayıtları görüntüleme 3.
cursor.fetchall()
fonksiyonu ile tüm kayıtlar alınabilir 3.
Örnek kod:
from kivy.lang import Builder from kivymd.app import MDApp import sqlite3 class MainApp(MDApp): def build(self): self.theme_cls.theme_style = "Dark" self.theme_cls.primary_palette = "BlueGray" conn = sqlite3.connect('first_db.db') # Veritabanını bağlama c = conn.cursor() # İmleç oluşturma # Tablo oluşturma c.execute("""CREATE TABLE if not exists customers( name text)""") # Kayıt ekleme c.execute("INSERT INTO customers VALUES (:first)", {'first': self.root.ids.word_input.text}) # Kayıtları görüntüleme c.execute("SELECT * FROM customers") records = c.fetchall() word = '' for record in records: word = f'{word}\n{record[0]}' self.root.ids.word_label.text = f'{word}' conn.close() # Bağlantıyı kapatma MainApp().run() # Uygulamayı çalıştırma
5 kaynaktan alınan bilgiyle göre: