RGBANK is a simple Python program that is designed to simulate a basic banking system. The program allows users to create an account, deposit and withdraw funds, and check their account balance. It is built using the PySimpleGUI library, which is a powerful and easy-to-use GUI toolkit for Python.
In this tutorial, we will walk through the process of setting up RGBANK using PySimpleGUI and explain how it works step by step.
Step 1: Install PySimpleGUI
Before we can start building our RGBANK program, we need to install the PySimpleGUI library. You can do this using pip by running the following command in your terminal:
pip install PySimpleGUI
Step 2: Import the necessary modules
Next, we need to import the necessary modules that will be used in our program. Create a new Python file and add the following lines of code:
import PySimpleGUI as sg
Step 3: Define the layout of the GUI
Now, let’s define the layout of our RGBANK program. We will create a simple GUI with input fields for the user to enter their account number, deposit or withdrawal amount, and buttons to perform the respective actions. Add the following code to define the layout:
layout = [
[sg.Text('Account Number:'), sg.InputText(key='account_number')],
[sg.Text('Amount:'), sg.InputText(key='amount')],
[sg.Button('Deposit'), sg.Button('Withdraw'), sg.Button('Check Balance')],
]
Step 4: Create the window
Next, we need to create the PySimpleGUI window using the layout that we defined in the previous step. Add the following code to create the window:
window = sg.Window('RGBANK', layout)
Step 5: Implement the functionality
Now, let’s implement the functionality of our RGBANK program. We will create a simple banking system that allows users to deposit or withdraw funds and check their account balance. Add the following code to handle user input and perform the respective actions:
account_balance = 0
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
if event == 'Deposit':
amount = float(values['amount'])
account_balance += amount
sg.popup('Deposit successful!')
elif event == 'Withdraw':
amount = float(values['amount'])
if amount <= account_balance:
account_balance -= amount
sg.popup('Withdrawal successful!')
else:
sg.popup('Insufficient funds!')
elif event == 'Check Balance':
sg.popup(f'Your account balance is: ${account_balance}')
Step 6: Run the program
Finally, run the RGBANK program by adding the following code at the end of your script:
window.close()
Now you can run the program and test it by entering your account number, depositing or withdrawing funds, and checking your account balance.
This tutorial has provided a simple introduction to building a basic banking system using PySimpleGUI in Python. You can further enhance the functionality of RGBANK by adding features such as account creation, transactions history, and more. Feel free to experiment with the code and customize it to suit your needs.
Muito bacana, Renato!
Algum dos seus projetos você utilizou integração com Banco de Dados?