This is a Python graphical application that manages an employee database. The application handles tasks such as establishing a database connection, creating an employee table, inserting, querying, updating, and deleting employee records and information within the company.
The following libraries are imported for the application:
sqlite3
andError
fromsqlite3
: for database operationstkinter
andmessagebox
: for creating the graphical user interface
The crear_conexion()
function is responsible for creating a connection to the database. It uses the SQLite library and returns the connection object.
The crear_tabla(conn)
function creates the employee table if it does not already exist. The table has the following columns:
id
: integer (primary key)nombre
: text (not null)cargo
: text (not null)salario
: real
The insertar_empleado(conn, empleado)
function inserts an employee record into the database. It takes the employee's name, position, and salary as parameters and returns the ID of the newly inserted record.
The consultar_empleados(conn)
function retrieves all employee records from the database and prints them.
The actualizar_empleado(conn, empleado)
function updates an existing employee record. It takes the updated employee information (name, position, salary, and ID) as parameters and commits the changes to the database.
The eliminar_empleado(conn, id)
function deletes an employee record from the database based on the provided ID.
The crear_ventana()
function creates the main application window using the Tkinter library. The window title is set to "Employee Management" and its dimensions are set to 800x600 pixels.
The application window contains the following user interface elements:
- Text fields for entering employee name, position, salary, and ID
- Buttons for inserting an employee, querying employees, loading an employee, updating an employee, and deleting an employee
- A text area for displaying query results
- Run the application.
- Enter the employee's name, position, and salary in the corresponding text fields.
- Click the "Insert Employee" button to add the employee to the database.
- Click the "Query Employees" button to display all employee records.
- Enter an employee ID in the designated field and click the "Load Employee" button to load the employee's information for updating or deletion.
- Make the necessary changes in the text fields for updating an employee's information, and click the "Update Employee" button to save the changes.
- To delete an employee, enter the employee's ID in the designated field and click the "Delete Employee" button.
Please note that this application assumes the existence of a SQLite database file named "empleados_db.sqlite" in the same directory as the application file.
Feel free to explore the code and modify it according to your needs.