GUI Python Based Q&A Program 3

preview_player
Показать описание
GUI Python Based Q&A Program 3

Here I cover the code in the "Delete Button", plus all functions called
by the same.
Рекомендации по теме
Комментарии
Автор

# Here is the source code for both files,
# zfe.py and zbe.py
#
#### zfe.py ###


from tkinter import *
import zbe #

rt=Tk()
rt.title("Questions dBase Management System.")


def dele_command():
if(not(e1.get("1.0", END)=="\n")):
x1=int(tt[0])
print(x1)
zbe.dele(x1)
# print("Record: ", selected_tuple[0], "deleted")
e1.delete("1.0", END)
e2.delete("1.0", END)
print(str(tt))
# lb1.delete(0, END)
# lb1.insert(END, "Deleted:" + str(tt))
view_command()

"""
def dele2_command():
be.dele(selected_tuple[0])
print("Record: ", selected_tuple[0], "deleted")
e1.delete("1.0", END)
e2.delete("1.0", END)
view_command()
"""

def clearit_command():
e1.delete('1.0', END)
e2.delete('1.0', END)
# e3.delete(0, END)
# e4.delete(0, END)


def updt_command():
if(not(e1.get("1.0", END))=="\n"):
zbe.updt(tt[0], e1.get("1.0", END), e2.get("1.0", END))
view_command()


def gdr(event): # gtr = get the record
global tt # target tuple
yoid=lb1.curselection()[0] # gets the
# actual nbr
# in: listbox
# lb1.curselection()[0] <== order nbr in dbase & listbox
tt=lb1.get(yoid) # get rec assoc'd w/yoid

# lb1.curselection()[0] <== order nbr in dbase & listbox
# tt[0] is the primary field: id, of that record.
# print(lb1.curselection()[0], tt[0])
e1.delete('1.0', END)
e1.insert(END, tt[1])
e2.delete('1.0', END)
e2.insert(END, tt[2])
# e3.delete(0, END)
# e3.insert(END, tt[3])
# e4.delete(0, END)
# e4.insert(END, tt[4])

def view_command():
lb1.delete(0, END)
for row in zbe.view():
lb1.insert(END, row)

def findit_command():
lb1.delete(0, END)
for row in zbe.findit(e1.get("1.0", 'end-1c').strip(), e2.get("1.0",

'end-1c').strip()):
lb1.insert(END, row)

def add_command():
if(not(e1.get("1.0", END)=="\n")):
zbe.addrec(e1.get("1.0", END), e2.get("1.0", END))
lb1.delete(0, END)
lb1.insert(END, (e1.get("1.0", END), e2.get("1.0", END)))
clearit_command()
view_command()

# functions are done
for side of pgm

r=2
#l0=Label(rt, text="")
# l0.grid(row=1, column=0)

Entry Variables
e1=Text(rt, height=6, width=20, font=('arial', 24, 'bold'))
e1.grid(row=r, column=1)

e2=Text(rt, height=6, width=35, font=('arial', 24, 'bold'))
e2.grid(row=r, column=2)


lb1=Listbox(rt, height=9, width = 50, font=('arial', 24, 'bold'))
lb1.grid(row=4, column=1, rowspan=9, \
columnspan=2)

sb=Scrollbar(rt)
sb.grid(row=3, column=4, rowspan=7)





lb1.bind('<<ListboxSelect>>', gdr)
# we gotta define the func gdr
# in the define cmds area, at the top
# g=get d=dat r=record


b1=Button(rt, text="Q&A Recs", width=10,

command=view_command)
b1.grid(row=0, column=0)

b2=Button(rt, text="Delete", width=10, command=dele_command)
b2.grid(row=1, column=0)

b3=Button(rt, text="Add Rec", width=10, height=5,

command=add_command)
b3.grid(row=2, column=0)

b4=Button(rt, text="Update", width=10, height=5,

command=updt_command)
b4.grid(row=3, column=0)

b5=Button(rt, text="Find", width=10, \
command=findit_command)
b5.grid(row=4, column=0)

b6=Button(rt, text="Clear", width=10, height=4,

command=clearit_command)
b6.grid(row=5, column=0)

b7=Button(rt, text="Exit", width=10, command=rt.destroy)
b7.grid(row=6, column=0)



#
rt.mainloop()



zbe.py
import sqlite3

def connect():

cur=conn.cursor()
cur.execute("CREATE TABLE \
IF NOT EXISTS qtable \
(id INTEGER PRIMARY KEY, \
q1 text, a1 text)")
conn.commit()
conn.close()

def addrec(mq1, ma1):

cur=conn.cursor()
mq1=mq1.rstrip()
ma1=ma1.rstrip()
cur.execute("INSERT INTO qtable VALUES(NULL, ?, ?)", (mq1, ma1, ))
conn.commit()
conn.close()

def dele(mid):

cur=conn.cursor()
cur.execute("DELETE FROM qtable WHERE id=?", (mid, ))
conn.commit()
conn.close()

def updt(mid, mq1="", ma1=""):

cur=conn.cursor()
mq1=mq1.rstrip()
ma1=ma1.rstrip()
cur.execute("UPDATE qtable SET q1=?, a1=? WHERE id=?", (mq1, ma1, mid, ))
conn.commit()
conn.close()

def view():

cur=conn.cursor()
cur.execute("SELECT * FROM qtable")
rows=cur.fetchall()
conn.close()
return rows

def findit(mq1="", ma1=""):

cur=conn.cursor()
print(mq1, ma1)
cur.execute("SELECT * FROM qtable WHERE q1=? or a1=?", (mq1, ma1, ))
rows=cur.fetchall()
conn.close()
return rows


connect()




#addrec("F.wall does layer 4:", "filtering")
#addrec("F.wall posits on:", "ingress/egress of nwk")
#addrec("wap in a rtr is a:", "w.less router")
#addrec("wap is actually a:", "bridge")
#addrec("wap extends wired nwk into:", "som'n that's wireless")

hobokengar
Автор

Sir George Boole KBE, Your humble follower doth express interminable gratitude for (1) key to the garage (the vids you have made re Python Gui Sqlite) and (2) the key taped to the wall for the Lotus therein (code provided in the comment). I be squealing tires all over dah hood now! (not bonnet). --the grateful newbie

ukey
Автор

Sir George Boole KBE, Your humble follower doth express interminable gratitude for (1) the key to the garage (the vids you have made re Python Gui Sqlite) and (2) the key taped to the wall for the Lotus Seven therein (code provided in the comment). I be squealing tires all over dah hood now! (not bonnet). --the grateful newbie

ukey