I'm making a Financial tracking application for a school project, so the algorithm is supposed to take a bank statement as csv file and make few calculation on them, the screen where you upload the .csv file goes completely unresponsive after i click the button to upload the file Here's the code:
import sqlite3
from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.uix.screenmanager import ScreenManager, Screen
from kivymd.uix.button import MDRaisedButton
from kivy.metrics import dp
from tkinter import Tk, filedialog
import pandas as pd
import numpy as np
KV = '''
ScreenManager:
InterfaceScreen:
<InterfaceScreen>:
BoxLayout:
orientation: 'vertical'
padding: dp(32)
MDLabel:
text: 'Interface'
halign: 'center'
font_style: 'H4'
size_hint_y: None
height: self.texture_size[1]
MDRaisedButton:
text: 'Load CSV'
on_release: root.load_csv()
size_hint_x: None
width: 300
pos_hint: {'center_x': 0.5}
'''
class InterfaceScreen(Screen):
def load_csv(self):
root = Tk()
root.withdraw() # Hide the main window
file_path = filedialog.askopenfilename(title="Select CSV File", filetypes=[("CSV files", "*.csv")])
root.destroy() # Close the hidden main window
if file_path:
self.process_csv(file_path)
def process_csv(self, file_path):
connection = sqlite3.connect('money.db')
cursor = connection.cursor()
try:
cursor.execute('''
CREATE TABLE IF NOT EXISTS money (
id INTEGER PRIMARY KEY AUTOINCREMENT,
money_in INTEGER,
money_out INTEGER
)
''')
df = pd.read_csv(file_path)
answer = input('What would you like to do now? ')
if answer.lower() == "money in":
specific_column = df.iloc[:, 3]
numeric_values = pd.to_numeric(specific_column, errors='coerce')
money_in_array = numeric_values[~numeric_values.isna()].to_numpy()
for money_in in money_in_array:
cursor.execute("INSERT INTO money (money_in) VALUES (?)", (money_in,))
connection.commit()
print("Money In Data Inserted Successfully!")
elif answer.lower() == "money out":
specific_column = df.iloc[:, 4]
numeric_values = pd.to_numeric(specific_column, errors='coerce')
money_out_array = numeric_values[~numeric_values.isna()].to_numpy()
for money_out in money_out_array:
cursor.execute("INSERT INTO money (money_out) VALUES (?)", (money_out,))
connection.commit()
print("Money Out Data Inserted Successfully!")
except Exception as e:
print(f"Error processing CSV: {e}")
finally:
connection.close()
class MyApp(MDApp):
def build(self):
self.create_user_database() # Create the user table if not exists
return Builder.load_string(KV)
def create_user_database(self):
connection = sqlite3.connect('users.db')
cursor = connection.cursor()
# Create the user table if not exists
cursor.execute('''
CREATE TABLE IF NOT EXISTS user (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT UNIQUE,
password TEXT
)
''')
connection.commit()
connection.close()
if __name__ == '__main__':
MyApp().run()
I really haven't tried anything yet because i really don't know how to solve it. Furthermore it was working the first time i coded it,