Python Forum
I don't know what is wrong (Python and SQL connection)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I don't know what is wrong (Python and SQL connection)
#3
Hope you don't mind but, I spruced up your app a little.
I didn't do any of the database functions as I don't really know what you are wanting them to do.
On a side note you have a delete and reset button. If you delete a record from the database, it can't be reset.

Here is the code
import tkinter as tk
import tkcalendar 

class Database:
    def __init__(self):
        pass 


class Window:
    def __init__(self, parent):
        # Set some parent window variables
        self.parent = parent
        self.parent.columnconfigure(0, weight=1)
        self.parent.rowconfigure(0, weight=1)
        # self.parent.geometry('1280x720+300+300')
        self.parent.title('Hospital Management System Version 0.01')

        # Create a main container frame widget. This will hold all other containers and widgets
        container = tk.Frame(self.parent)
        container.grid(column=0, row=0, sticky='news')
        container.grid_columnconfigure(0, weight=3)

        # Create a header for the app
        header = tk.Label(container, text='Hospital Management System', pady=8)
        header['font'] = None, 34, 'bold'
        header['bg'] = 'firebrick'
        header['fg'] = 'white'
        header.grid(column=0, row=0, sticky='news', padx=8, pady=4)

        # Create a container for widgets in row 1
        row1 = tk.Frame(container)
        row1.grid(column=0, row=1, sticky='news', padx=4, pady=4)

        # Divied the column space evenly
        row1.grid_columnconfigure(0, weight=3, uniform='row1')
        row1.grid_columnconfigure(1, weight=3, uniform='row1')

        # Container to hold all the entry widgets for patient
        infoframe = tk.LabelFrame(row1, text='Patient Information', font=(None, 11, 'bold'), padx=4, pady=4)
        infoframe.grid(column=0, row=0, sticky='news', padx=4, pady=4)
        for i in range(4):
            infoframe.grid_columnconfigure(i, weight=3)
        
        # Container to hold prescription information/listbox
        prescriptionframe = tk.LabelFrame(row1, text='Prescription', font=(None, 11, 'bold'))
        prescriptionframe.grid(column=1, row=0, sticky='news', padx=4, pady=4)
        prescriptionframe.grid_columnconfigure(0, weight=3)

        # List of patient fields
        data = ['Reference No', 'Issue Date', 'Appointment Date', 'Patient ID',
        'Patient Name', 'Date Of Birth', 'Patient Address', 'NHS Number', 'Use Medication', 'Doctor Name']
        thelist = ['Issue Date','Appointment Date', 'Date Of Birth']
        # Empty list to hold entry fields
        self.fields = []
        col, row = 0, 0

        for index, prefix in enumerate(data):
            label = tk.Label(infoframe, text=f'{prefix}:', anchor='w')

            # So entry prefix is in every other column
            if col % 2 == 0:
                col += 1
            label.grid(column=col, row=row, sticky='new', padx=2, pady=4)
            if prefix in thelist:
                self.fields.append(tkcalendar.DateEntry(infoframe))
            else:
                self.fields.append(tk.Entry(infoframe))
            self.fields[index].grid(column=col+1, row=row, sticky='new', padx=8, pady=4)

            if col >= 3:
                row += 1
                col = 0
            else:
                col += 1

        self.prescription = tk.Text(prescriptionframe, height=9)
        self.prescription.grid(column=0, row=0, sticky='news', padx=4, pady=4)

        # List for the buttons
        buttons = ['Prescription', 'Medication Details', 'Delete', 'Reset', 'Exit']
        buttonlist = []

        buttonframe = tk.LabelFrame(container, text='Actions', font=(None, 11, 'bold'))
        buttonframe.grid(column=0, row=2, sticky='news', padx=4, pady=4)
        for i in range(len(buttons)):
            buttonframe.grid_columnconfigure(i, weight=3, uniform='button')

        for index, button in enumerate(buttons):
            if button == 'Exit':
                color = 'orangered'
                activecolor = 'orange'
            elif button == 'Delete':
                color = 'tomato'
                activecolor = 'red'
            else:
                color = 'powderblue'
                activecolor = 'skyblue'
            buttonlist.append(tk.Button(buttonframe, text=button, bg=color, cursor='hand2'))
            buttonlist[index]['activebackground'] = activecolor
            buttonlist[index].grid(column=index, row=0, sticky='news', padx=4, pady=4)


        extra = tk.LabelFrame(container)
        extra['text'] = 'Type of medical condition / Does the patient use medications?'
        extra.grid(column=0, row=3, sticky='news', padx=4, pady=4)
        extra.grid_columnconfigure(0, weight=3)

        self.extra = tk.Text(extra)
        self.extra.grid(column=0, row=0, sticky='news' ,padx=4, pady=4)




class Controller:
    def __init__(self, database, window):
        self.database = database 
        self.window = window 


if __name__ == '__main__':
    root = tk.Tk()
    controller = Controller(Database(), Window(root))
    root.mainloop()

Attached Files

Thumbnail(s)
   
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
RE: I don't know what is wrong (Python and SQL connection) - by menator01 - Mar-28-2024, 06:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  No Internet connection when running a Python script basil_555 8 837 Mar-11-2024, 11:02 AM
Last Post: snippsat
  Connection LTspice-Python with PyLTSpice bartel90 0 430 Feb-05-2024, 11:46 AM
Last Post: bartel90
  Virtual Env changing mysql connection string in python Fredesetes 0 435 Dec-20-2023, 04:06 PM
Last Post: Fredesetes
  connection python and SQL dawid294 4 807 Dec-12-2023, 08:22 AM
Last Post: Pedroski55
  Networking Issues - Python GUI client and server connection always freezes Veritas_Vos_Liberabit24 0 790 Mar-21-2023, 03:18 AM
Last Post: Veritas_Vos_Liberabit24
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,768 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  Python MYSQL connection does not work after 1h idle zazas321 9 7,131 Oct-07-2021, 12:02 PM
Last Post: ndc85430
  Serial connection connection issue Joni_Engr 15 8,399 Aug-30-2021, 04:46 PM
Last Post: deanhystad
  How can I make a plot representing connection relationship with python matplotlib? Berlintofind 1 2,009 May-08-2020, 09:27 PM
Last Post: jefsummers
  Connection DATABASE to Python MenThoLLt 3 2,503 Jan-17-2020, 10:35 PM
Last Post: DT2000

Forum Jump:

User Panel Messages

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