Hi, I’m totally stuck and quite new to all this, I am trying to update the second column, so when the user clicks submit, the database will update with that number. I know I have to call a function, but struggling because I cant use two add commands on the same button.
Any help is appreciated.
from sqlite3.dbapi2 import Cursor, Row
import tkinter as tk
from tkinter import Button, Label, Pack, ttk
from tkinter import *
import backend
import sqlite3
#############################################################################
root = tk.Tk()
style = ttk.Style(root)
style.configure('lefttab.TNotebook', tabposition='wn')
notebook = ttk.Notebook(root, style='lefttab.TNotebook')
f1 = tk.Frame(notebook, bg='whitesmoke', width=1200, height=868)
notebook.add(f1, text='Types Of Car ')
notebook.grid(row=0, column=0, sticky="nw")
###############################################################################
max_amount = 0
mylabel = 0
def Update_transfer():
global max_amount, label1
max_amount +=1
mylabel.configure(text="Transfer to Cust services:" + str(max_amount))
update_transfer_by_1 =str(max_amount)
mylabel = Label(f1,text="Transfer to Cust services: " + update_transfer_by_1, )
mylabel.place(relx=0.4, rely=0.3, width=300, height=55)
mylabel.config(bg='lightgreen', padx=0, font=("times new roman", 16))
submit_merc = Button(f1, text="submit", padx=50, command = Update_transfer, )
submit_merc.place (relx=0.4, rely=0.4, )
#################################################################################
root.mainloop()```
BACKEND:
import sqlite3
def connect():
conn=sqlite3.connect(“cars.db”)
cur=conn.cursor()
cur.execute(“CREATE TABLE IF NOT EXISTS car ( name text, amount integer)”)
conn.commit()
conn.close()
def insert(name, amount):
conn=sqlite3.connect(“cars.db”)
cur=conn.cursor()
cur.execute(“INSERT INTO car VALUES (?, ?)”,(name, amount))
conn.commit()
conn.close()
def view():
conn=sqlite3.connect(“cars.db”)
cur=conn.cursor()
cur.execute(“SELECT * FROM car”)
rows=cur.fetchall()
conn.close
return rows
def search(name="", amount=""):
conn=sqlite3.connect(“cars.db”)
cur=conn.cursor()
cur.execute(“SELECT * FROM car WHERE name =? OR amount =?”,(name, amount))
rows=cur.fetchall()
conn.close
return rows
connect()
#insert(“transfer”, “19”)
#print(view())