Python Forum
[Tkinter] enter data with keypad
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] enter data with keypad
#1
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 Sad 

#!/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()
Reply
#2
Please don't double post and use code tags.
Reply
#3
You can get the data using an entry widget, see: http://infohost.nmt.edu/tcc/help/pubs/tk...entry.html
As far as using the keypad, if you need to bind specific keys see: http://infohost.nmt.edu/tcc/help/pubs/tk...names.html
Reply
#4
(Feb-11-2017, 01:54 PM)Larz60+ Wrote: You can get the data using an entry widget, see: http://infohost.nmt.edu/tcc/help/pubs/tk...entry.html
As far as using the keypad, if you need to bind specific keys see: http://infohost.nmt.edu/tcc/help/pubs/tk...names.html

this training is reated 'keyboard' keys not keypad..and i just want to show (the number that is pressed) in an entry box...in my oponion, 'bind' is not suitable for my work.
Reply
#5
Quote:The .keysym_num column shows a numeric code equivalent to the key symbol. Unlike .keycode, these codes are different for different modifiers. For example, the digit 2 on the numeric keypad (key symbol KP_2) and the down arrow on the numeric keypad (key symbol KP_Down) have the same key code (88), but different .keysym_num values (65433 and 65458, respectively).
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  ON-SCREEN KEYPAD module ATARI_LIVE 1 2,150 Sep-30-2020, 12:19 PM
Last Post: Larz60+
  [Tkinter] Keypad Not Aligned sappc74 7 5,508 Feb-09-2019, 05:51 PM
Last Post: woooee
  [Tkinter] Tkinter Entry widget and KeyPad intrgration chiragarya1992 0 7,690 Aug-11-2018, 01:09 AM
Last Post: chiragarya1992

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020