hello friends
i want to comminucate between keypad & tkinter.
i used from ‘sql’ to create a data table.how can i enter my data into ‘id’ entry by keypad not keyboard?
i got the error ‘‘cursor object doesnt have ‘set’ or ‘insert’ attribute’’ while using command ‘c.set’ and ‘c.insert’ (c is ‘id’ entry)
then what shoud i do?
please help
#!/usr/bin/python3.2
# https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=100039
from tkinter import *
import RPi.GPIO as GPIO
import sqlite3
conn = sqlite3.connect('database.db')
c = conn.cursor()
#sudo python3.2 test3.py
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
MATRIX=[[1,2,3,'A'],
[4,5,6,'B'],
[7,8,9,'C'],
['*',0,'S','D']]
ROW=[7,11,13,15]
COL=[12,16,18,22]
for j in range(4):
GPIO.setup(COL[j],GPIO.OUT)
GPIO.output(COL[j],1)
for i in range(4):
GPIO.setup(ROW[i],GPIO.IN,pull_up_down=GPIO.PUD_UP)
##global cl1
##global cl2
class App:
def __init__(self,master):
## frame = Frame(master)
## frame.pack()
self.master=master
a= StringVar()
b= StringVar()
a1= StringVar()
b1= StringVar()
c= StringVar()
self.button = Button(self.master,text="open", fg="red", command=self.ouvrir)
self.button.pack(side=LEFT)
self.button2 = Button(self.master,text="create", command=self.tabluh)
self.button2.pack(side=LEFT)
self.button3 = Button(self.master,text="close DB", command=self.fermer)
self.button3.pack(side=LEFT)
self.button31=Button(self.master,text="Exit",fg='red',command=self.exit)
self.button31.pack(side=LEFT)
self.button4 = Button(self.master,text="insert rec", command=self.insertar)
self.button4.pack(side=LEFT)
self.button5 = Button(self.master,text="list rec", command=self.listar)
self.button5.pack(side=LEFT)
self.a = Entry(self.master)
self.a.pack(side=BOTTOM)
self.b = Entry(self.master)
self.b.pack(side=BOTTOM)
self.c = Entry(self.master)
self.c.pack(side=BOTTOM)
## def runit():
## global cl1
## global cl2
## global go
## for j in range(4):
## GPIO.output(COL[j],0)
## for i in range(4):
##
## if GPIO.input(ROW[i])==0:
##
## print (MATRIX[i][j]),
## self.c.insert(10,MATRIX[i][j])
##
##
## while(GPIO.input(ROW[i])==0):
## pass
## ## time.sleep(0.1)
## GPIO.output(COL[j],1)
##
#### root.after(10,runit)
#### root.after(10,runit)
def ouvrir(self):
self.con=sqlite3.connect('maddb')
self.cur=self.con.cursor()
def tabluh(self):
c.execute('''CREATE TABLE xxx(id INTEGER,firs stringvar(10),las stringvar(10))''')
def fermer(self):
self.con.close()
def insertar(self):
a1=self.a.get()
b1=self.b.get()
c1=int(self.c.get())
c.execute("INSERT INTO xxx (id, firs,las ) VALUES (?, ?, ?)",(c1, a1, b1))
conn.commit()
def listar(self):
## c.execute('SELECT * FROM xxx')
## print(c.fetchall())
root2=Toplevel(self.master)
mygui=records(root2)
def exit(self):
#Exit protocol for the exit button. This part is completely done.#
self.master.destroy()
## App.after(10,runit)
class records():
#class created to see records that have been previously inputted#
def __init__(self,master):
self.master=master
## self.master.geometry('250x200+100+200')
self.master.geometry('400x200')
self.master.title('Records')
self.connection = sqlite3.connect('database.db')
self.cur = self.connection.cursor()
self.dateLabel = Label(self.master, text="ID", width=10)
self.dateLabel.grid(row=0, column=0)
self.BMILabel = Label(self.master, text="firstname", width=10)
self.BMILabel.grid(row=0, column=1)
self.stateLabel = Label(self.master, text="lastname", width=10)
self.stateLabel.grid(row=0, column=2)
self.button6 = Button(self.master,text="Delete", command=self.delete_item)
self.button6.grid(row=1, column=3)
self.showallrecords()
def showallrecords(self):
data = self.readfromdatabase()
for index, dat in enumerate(data):
Label(self.master, text=dat[0]).grid(row=index+1, column=0)
Label(self.master, text=dat[1]).grid(row=index+1, column=1)
Label(self.master, text=dat[2]).grid(row=index+1, column=2)
def readfromdatabase(self):
self.cur.execute("SELECT * FROM xxx")
return self.cur.fetchall()
def delete_item(self):
"""
delete a selected line from the listbox
"""
try:
# get selected line index
index = self.master.curselection()[0]
self.master.delete(index)
except IndexError:
pass
def runit():
global cl1
global cl2
global go
for j in range(4):
GPIO.output(COL[j],0)
for i in range(4):
if GPIO.input(ROW[i])==0:
print (MATRIX[i][j]),
c.set(10,MATRIX[i][j])
while(GPIO.input(ROW[i])==0):
pass
## time.sleep(0.1)
GPIO.output(COL[j],1)
root.after(10,runit)
##def labelshow():
## if cl1 == 1:
## label1.pack()
## label1.update()
## root.after(500)
## label1.pack_forget()
##
##
## root.after(20,labelshow)
root = Tk()
root.after(10,runit)
app=App(root)
root.mainloop()