Skip to content

Instantly share code, notes, and snippets.

@SyntaxError843
Last active November 24, 2021 08:27
Show Gist options
  • Save SyntaxError843/e910c56652327a59e0bf17c0abdc9a48 to your computer and use it in GitHub Desktop.
Save SyntaxError843/e910c56652327a59e0bf17c0abdc9a48 to your computer and use it in GitHub Desktop.
from tkinter import *
from tkinter import ttk
import tksheet
donors = []
found_donors = []
# Donors application form
root = Tk()
root.geometry("1280x640")
root.title("Donors")
# Patients search form
patients = Tk()
patients.geometry("1280x640")
patients.title("Patients")
sheet = tksheet.Sheet( root, width = 1000, headers = ( 'First Name', 'Last Name', 'Phone Number', 'Age', 'Blood Type' ) )
donors_sheet = tksheet.Sheet( patients, width = 480, headers = ( 'Full Name', 'Phone Number' ) )
YES_NO_ANSWERS = (
'No',
'Yes',
)
BLOOD_TYPES = (
'A-',
'A+',
'B-',
'B+',
'AB-',
'AB+',
'O-',
'O+',
)
def get_donors_by_blood_type() :
# Clear found donors
found_donors.clear()
# Get blood type to search by
blood_type_search = patient_blood_type.get()
if ( blood_type_search != '' ) :
for donor in donors :
if blood_type_search == donor['blood_type'] :
found_donors.append({
'full_name' : ( donor['first_name'] + ' ' + donor['last_name'] ),
'phone_number' : donor['phone_number'],
})
update_found_donors_table()
def update_found_donors_table() :
donors_sheet.set_sheet_data( [ list( donor.values() ) for donor in found_donors ] )
def update_donors_table() :
sheet.set_sheet_data( [ list( donor.values() ) for donor in donors ] )
def save_donor() :
# Get donor first name
donor_first_name = first_name.get().title()
# Get donor last name
donor_last_name = last_name.get().title()
# Get donor phone number
donor_phone_number = phone_number.get()
# Get donor age
donor_age = age.get()
# Get donor disease response
donor_disease = disease.get()
# Get donor blood type
donor_blood_type = blood_type.get()
# Check if required fields are empty
# Check if age > 18
# Check if no disease
if ( donor_first_name != '' and donor_last_name != '' and donor_phone_number != ''
and donor_age.isdigit() and int( donor_age ) > 18 and donor_disease == 'No' ) :
donors.append({
'first_name' : donor_first_name,
'last_name' : donor_last_name,
'phone_number' : donor_phone_number,
'age' : int( donor_age ),
'blood_type' : donor_blood_type,
})
update_donors_table()
# Clear all input fields
first_name.delete( 0, END )
last_name.delete( 0, END )
phone_number.delete( 0, END )
age.delete( 0, END )
disease.set( YES_NO_ANSWERS[0] )
blood_type.set( BLOOD_TYPES[0] )
# Main Title
ttk.Label(root, padding=10, text="Blood Donors Application Form", font=("Calibri",40)).pack()
# Description
ttk.Label(root, padding=20, text="Please fill out the below form to register as a blood donor!", font=("Calibri",16)).pack()
# First name
ttk.Label( root, padding=5, text='First Name' ).pack()
first_name = Entry(root)
first_name.pack()
# Last name
ttk.Label( root, padding=5, text='Last Name' ).pack()
last_name = Entry(root)
last_name.pack()
# Phone Number
ttk.Label( root, padding=5, text='Phone Number' ).pack()
phone_number = Entry(root)
phone_number.pack()
# Age
ttk.Label( root, padding=5, text='Age' ).pack()
age = Entry(root)
age.pack()
# Has disease
ttk.Label( root, padding=10, text='Do you suffer from any blood related diseases?' ).pack()
disease = StringVar( root )
disease.set( YES_NO_ANSWERS[0] )
OptionMenu(root, disease, *YES_NO_ANSWERS).pack()
# Blood type
ttk.Label( root, padding=10, text='Blood Type' ).pack()
blood_type = StringVar( root )
blood_type.set( BLOOD_TYPES[0] )
OptionMenu(root, blood_type, *BLOOD_TYPES).pack()
# Submit button
Button( root, text="Submit", command=save_donor ).pack()
# Show donors
ttk.Label( root, padding=20, text='Accepted Donors', font=( 'Calibri', 16 ) ).pack()
sheet.pack()
update_donors_table()
# Patients form code
# Main Title
ttk.Label(patients, padding=10, text="Patients Application Form", font=("Calibri",40)).pack()
# Description
ttk.Label(patients, padding=20, text="Please select a blood type.", font=("Calibri",16)).pack()
# Blood type
ttk.Label( patients, padding=10, text='Blood Type' ).pack()
patient_blood_type = StringVar( patients )
patient_blood_type.set( BLOOD_TYPES[0] )
OptionMenu(patients, patient_blood_type, *BLOOD_TYPES).pack()
# Submit button
Button( patients, text="Submit", command=get_donors_by_blood_type ).pack()
# Show found donors
ttk.Label( patients, padding=20, text='Found Donors', font=( 'Calibri', 16 ) ).pack()
donors_sheet.pack()
update_found_donors_table()
root.mainloop()
patients.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment