1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
# simple criteria or multi-criteria search functions
# function callback
def callbackAuteur(event):
print(cmb_attribution.get()) # DEBUG
rslcmb = cmb_attribution.get()
def cmb_auteur2():
""" Data recovery and insertion in combobox author_citation """
connexion = sqlite3.connect('mnesis.db')
cursor = connexion.cursor()
cursor.execute('SELECT auteur FROM tb_auteur ORDER BY auteur')
data1 = []
for row in cursor.fetchall():
data1.append(row[0])
return data1
def queryQuoteforauteur():
""" Returns the values of the records of the Database """
connexion = sqlite3.connect('mnesis.db')
cursor = connexion.cursor()
rsl = rslcmb
cursor.execute('SELECT * FROM tb_citation WHERE auteur=?', (rsl,))
print(f"SELECT * FROM tb_citation WHERE auteur = '{rsl}'") # DEBUG
resultDatabase = cursor.fetchall()
results = ''
for row in resultDatabase:
results += '\n'.join({
'Auteur: {}'.format(row[1]),
'Citation: {}'.format(row[2]),
'Référence: {}'.format(row[3]),
'-----------------------\n'
})
connexion.close()
return results
def result_quote():
""" Returns the values of the database records """
tpl_result = Toplevel() # == Contructor Toplevel ==
tpl_result.title(" Data display")
tpl_result.geometry("1024x600")
# Text area with scrollbar
zonetext = tk.Text()
zonetext = ScrolledText(tpl_result, width=120, height=35)
zonetext.pack()
resulreq = query_quote()
zonetext.insert("0.0", resulreq)
# end of the loop ---
tpl_result.mainloop()
def search_data():
"""
Search by selection of a combobox
"""
global tpl_search
tpl_search = Toplevel() # == Constructor Toplevel ==
tpl_search.title(" Search by selection of a combobox")
screen_x = int(tpl_search.winfo_screenwidth())
screen_y = int(tpl_search.winfo_screenheight())
tpl_search_x = 400
tpl_search_y = 100
pos_x = (screen_x // 2) - (tpl_search_x // 2)
pos_y = (screen_y // 2) - (tpl_search_y // 2)
geo = "{}x{}+{}+{}".format(tpl_search_x, tpl_search_y, pos_x, pos_y)
tpl_search.geometry(geo)
tpl_search.resizable(width=False, height=False) # Editable window True or False
tpl_search.configure(bg='Gray79')
# ------------
attribution_label = Label(tpl_search, text="Author", bg='Gray79', font=("Arial", 11, "bold"))
attribution_label.place(x=100, y=25)
cmb_attribution = ttk.Combobox(tpl_search, values=cmb_auteur2(), width=20, height=30,
font=("Arial", 10, "bold"))
cmb_attribution.bind('<<ComboboxSelected>>', cmb_auteur2)
cmb_attribution.place(x=100, y=46)
# ----
record_btn = Button(tpl_search, text='Launch', activebackground="SkyBlue1", font=("Arial", 8),
command=lambda: queryQuoteforauteur())
record_btn.place(x=280, y=46)
# end of the loop ---
tpl_search.mainloop() |
Partager