Thank you Al, Matthew and Paul for your quick reply. I am attaching the full code for BooksLibrary_Support.py.
import sys
import tkinter as tk
import tkinter.ttk as ttk
from tkinter.constants import *
import BooksLibrary
# import the sqlite3 module
import sqlite3
vCat=""
vTit=""
vAuth=""
vYear=int()
vComments=""
# Define connection to Book DB and cursor
conn = sqlite3.connect("Books.db")
curs = conn.cursor()
_debug = True # False to eliminate debug printing from callback functions.
def main(*args):
'''Main entry point for the application.'''
global root
root = tk.Tk()
root.protocol( 'WM_DELETE_WINDOW' , root.destroy)
# Creates a toplevel widget.
global _top1, _w1
_top1 = root
_w1 = BooksLibrary.BooksLibrary(_top1)
root.mainloop()
def on_btnAddClick(*args):
vCat=("Category")
vTit=("Title")
vAuth=("Author")
vYear=("Year_Purchased")
vComments=("Comments")
curs.execute("INSERT INTO Books(Category,Title,Author,Year_Purchased,\
Comments) VALUES(?, ?, ?,?,?)", (vCat,vTit,vAuth,vYear,\
vComments) );
conn.commit()
def on_btnDeleteClick(*args):
if _debug:
print('BooksLibrary_support.on_btnDeleteClick')
for arg in args:
print (' another arg:', arg)
sys.stdout.flush()
def on_btnEditClick(*args):
if _debug:
print('BooksLibrary_support.on_btnEditClick')
for arg in args:
print (' another arg:', arg)
sys.stdout.flush()
def on_btnExitClick(*args):
root.destroy()
def on_btnUpdateClick(*args):
if _debug:
print('BooksLibrary_support.on_btnUpdateClick')
for arg in args:
print (' another arg:', arg)
sys.stdout.flush()
if __name__ == '__main__':
BooksLibrary.start_up()
The other program BooksLibrary.py that creates the form was generated by using the Page GUI program and is also below;
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
#
# GUI module generated by PAGE version 8.0
# in conjunction with Tcl version 8.6
# Nov 24, 2024 11:50:48 AM GMT platform: Darwin
import sys
import tkinter as tk
import tkinter.ttk as ttk
from tkinter.constants import *
import os.path
_location = os.path.dirname(__file__)
import BooksLibrary_support
_bgcolor = 'wheat'
_fgcolor = 'black'
_tabfg1 = 'black'
_tabfg2 = 'white'
_bgmode = 'light'
_tabbg1 = '#d9d9d9'
_tabbg2 = 'gray40'
_style_code_ran = 0
def _style_code():
global _style_code_ran
if _style_code_ran: return
try: BooksLibrary_support.root.tk.call('source',
os.path.join(_location, 'themes', 'new-wheat.tcl'))
except: pass
style = ttk.Style()
style.theme_use('new-wheat')
style.configure('.', font = "TkDefaultFont")
_style_code_ran = 1
class BooksLibrary:
def __init__(self, top=None):
'''This class configures and populates the toplevel window.
top is the toplevel containing window.'''
top.geometry("360x390+572+464")
top.minsize(72, 15)
top.maxsize(1600, 847)
top.resizable(1, 1)
top.title("Books Library")
top.configure(background="wheat")
top.configure(highlightbackground="wheat")
top.configure(highlightcolor="black")
self.top = top
self.combobox = tk.StringVar()
_style_code()
self.lblYearPub = ttk.Label(self.top)
self.lblYearPub.place(relx=0.053, rely=0.441, height=21, width=94)
self.lblYearPub.configure(font="-family {.AppleSystemUIFont} -size 13")
self.lblYearPub.configure(relief="flat")
self.lblYearPub.configure(text='''Year Published''')
self.lblYearPub.configure(compound='left')
self.eAuthor = ttk.Entry(self.top)
self.eAuthor.place(relx=0.361, rely=0.359, relheight=0.059
, relwidth=0.481)
self.eAuthor.configure(font="-family {.AppleSystemUIFont} -size 13")
self.eAuthor.configure(cursor="ibeam")
self.eYearPub = ttk.Entry(self.top)
self.eYearPub.place(relx=0.361, rely=0.441, relheight=0.062
, relwidth=0.208)
self.eYearPub.configure(font="-family {.AppleSystemUIFont} -size 13")
self.eYearPub.configure(cursor="ibeam")
self.eTitle = ttk.Entry(self.top)
self.eTitle.place(relx=0.361, rely=0.274, relheight=0.062
, relwidth=0.481)
self.eTitle.configure(font="-family {.AppleSystemUIFont} -size 13")
self.eTitle.configure(cursor="ibeam")
self.lblTitle = ttk.Label(self.top)
self.lblTitle.place(relx=0.053, rely=0.274, height=22, width=38)
self.lblTitle.configure(font="-family {.AppleSystemUIFont} -size 13")
self.lblTitle.configure(relief="flat")
self.lblTitle.configure(text='''Title''')
self.lblTitle.configure(compound='left')
self.btnExit = ttk.Button(self.top)
self.btnExit.place(relx=0.542, rely=0.826, height=26, width=90)
self.btnExit.configure(command=BooksLibrary_support.on_btnExitClick)
self.btnExit.configure(text='''Exit''')
self.btnExit.configure(compound='left')
self.btnDelete = ttk.Button(self.top)
self.btnDelete.place(relx=0.694, rely=0.674, height=26, width=70)
self.btnDelete.configure(command=BooksLibrary_support.on_btnDeleteClick)
self.btnDelete.configure(text='''Delete''')
self.btnDelete.configure(compound='left')
self.lblCategory = ttk.Label(self.top)
self.lblCategory.place(relx=0.053, rely=0.192, height=22, width=65)
self.lblCategory.configure(font="-family {.AppleSystemUIFont} -size 13")
self.lblCategory.configure(relief="flat")
self.lblCategory.configure(text='''Category''')
self.lblCategory.configure(compound='left')
self.btnEdit = ttk.Button(self.top)
self.btnEdit.place(relx=0.278, rely=0.674, height=26, width=65)
self.btnEdit.configure(command=BooksLibrary_support.on_btnEditClick)
self.btnEdit.configure(text='''Edit''')
self.btnEdit.configure(compound='left')
self.btnUpdate = ttk.Button(self.top)
self.btnUpdate.place(relx=0.472, rely=0.674, height=26, width=75)
self.btnUpdate.configure(command=BooksLibrary_support.on_btnUpdateClick)
self.btnUpdate.configure(text='''Update''')
self.btnUpdate.configure(compound='left')
self.btnAdd = ttk.Button(self.top)
self.btnAdd.place(relx=0.083, rely=0.674, height=26, width=65)
self.btnAdd.configure(command=BooksLibrary_support.on_btnAddClick)
self.btnAdd.configure(text='''Add''')
self.btnAdd.configure(compound='left')
self.lblComments = ttk.Label(self.top)
self.lblComments.place(relx=0.053, rely=0.523, height=21, width=70)
self.lblComments.configure(font="-family {.AppleSystemUIFont} -size 13")
self.lblComments.configure(relief="flat")
self.lblComments.configure(text='''Comments''')
self.lblComments.configure(compound='left')
self.cmbCategory = ttk.Combobox(self.top)
self.cmbCategory.place(relx=0.361, rely=0.192, relheight=0.062
, relwidth=0.517)
self.value_list = ['Horror,','Historical,','Literary,','Mystery,','Romance,','Science','Fiction,','Thriller',]
self.cmbCategory.configure(values=self.value_list)
self.cmbCategory.configure(font="-family {.AppleSystemUIFont} -size 13")
self.cmbCategory.configure(textvariable=self.combobox)
self.eRecNo = ttk.Entry(self.top)
self.eRecNo.place(relx=0.361, rely=0.11, relheight=0.062, relwidth=0.208)
self.eRecNo.configure(font="-family {.AppleSystemUIFont} -size 13")
self.eRecNo.configure(cursor="ibeam")
self.lblAuthor = ttk.Label(self.top)
self.lblAuthor.place(relx=0.053, rely=0.359, height=21, width=47)
self.lblAuthor.configure(font="-family {.AppleSystemUIFont} -size 13")
self.lblAuthor.configure(relief="flat")
self.lblAuthor.configure(text='''Author''')
self.lblAuthor.configure(compound='left')
self.lblRecNo = ttk.Label(self.top)
self.lblRecNo.place(relx=0.053, rely=0.11, height=21, width=57)
self.lblRecNo.configure(font="-family {.AppleSystemUIFont} -size 13")
self.lblRecNo.configure(relief="flat")
self.lblRecNo.configure(text='''Record #''')
self.lblRecNo.configure(compound='left')
self.eComments = ttk.Entry(self.top)
self.eComments.place(relx=0.361, rely=0.523, relheight=0.062
, relwidth=0.481)
self.eComments.configure(font="-family {.AppleSystemUIFont} -size 13")
self.eComments.configure(cursor="ibeam")
def start_up():
BooksLibrary_support.main()
if __name__ == '__main__':
BooksLibrary_support.main()
The only button I have tried to program is the Add button, so the others are more place holders…
Finally, I am not a programmer - just an 89 year old hobbyist who has loved computers since the advent of the Apple in 1978 - and now needs to keep his mind active.
So thank you all very much.