From de1661eee00f6a1f3450022330c6c1da6c842034 Mon Sep 17 00:00:00 2001 From: enosras Date: Mon, 29 Sep 2025 11:41:13 -0700 Subject: [PATCH 1/7] Create python-app.yml a test for the yml paradigm --- .github/workflows/python-app.yml | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/python-app.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..1168bd9 --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,39 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python application + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest From 163fe93eea2ebf1fe711dca540d07d2b56bb27fa Mon Sep 17 00:00:00 2001 From: Sri Nanak Date: Mon, 29 Sep 2025 08:53:58 -0700 Subject: [PATCH 2/7] set up a module for connections, following the mysql.connector module --- trial2.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 trial2.py diff --git a/trial2.py b/trial2.py new file mode 100644 index 0000000..67a7320 --- /dev/null +++ b/trial2.py @@ -0,0 +1,28 @@ +import mysql.connector +import mysql + +try: + connection = (mysql.connector.connect + ( + host='localhost', + user='enos', + password='2025@Redmond', + database='trial_1' + ) + ) + + if connection.is_connected(): + print("Successfully connected to MySQL database.") + # You can now create a cursor and execute SQL queries + # cursor = connection.cursor() + # cursor.execute("SELECT * FROM your_table") + # results = cursor.fetchall() + # print(results) + +except mysql.connector.Error as err: + print(f"Error connecting to MySQL: {err}") + +finally: + if 'connection' in locals() and connection.is_connected(): + connection.close() + print("MySQL connection closed.") \ No newline at end of file From b9704a66244cbb38bd26e51d7c2a85fea01a7e18 Mon Sep 17 00:00:00 2001 From: Sri Nanak Date: Mon, 29 Sep 2025 09:04:09 -0700 Subject: [PATCH 3/7] set up a module for connections, following the mysql.connector module. Also tested the app with a trial_1 table --- trial2.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/trial2.py b/trial2.py index 67a7320..f23fe6f 100644 --- a/trial2.py +++ b/trial2.py @@ -13,11 +13,12 @@ if connection.is_connected(): print("Successfully connected to MySQL database.") + # You can now create a cursor and execute SQL queries - # cursor = connection.cursor() - # cursor.execute("SELECT * FROM your_table") - # results = cursor.fetchall() - # print(results) + cursor = connection.cursor() + cursor.execute("SELECT * FROM trial_1") + results = cursor.fetchall() + print(results) except mysql.connector.Error as err: print(f"Error connecting to MySQL: {err}") From 3c58ce12e31029646e15bd4a084130e0af74db0e Mon Sep 17 00:00:00 2001 From: Sri Nanak Date: Mon, 29 Sep 2025 09:07:38 -0700 Subject: [PATCH 4/7] well done --- trial1.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/trial1.py b/trial1.py index 3b21281..8002571 100755 --- a/trial1.py +++ b/trial1.py @@ -1,6 +1,13 @@ import tkinter as tki from time import sleep +import dbm as db_connect +mydb = mysql.connector.connect( + host="localhost", # Your MySQL host + user="root", # Your MySQL username + password="2025@Redmond", # Your MySQL password + database="trial_1" # The database you want to connect to + ) def on_button_click(): """Function to be called when the button is clicked.""" @@ -16,8 +23,12 @@ def clear_label(): selected_option.set(options [0]) def save_trial (): name_variable = entry_widget.get() - label.config(text=f' Bye {name_variable} , your money is coming') - sleep(2) + + if name_variable == "": + label.config(text=f' Enter the name please') + else: + label.config(text=f' Bye {name_variable} , your money is coming') + sleep(2) # Create the main application window root = tki.Tk() From a12d7889eac7de7c1d8ba621b7433b2f6d3f51fc Mon Sep 17 00:00:00 2001 From: Sri Nanak Date: Mon, 29 Sep 2025 18:43:59 -0700 Subject: [PATCH 5/7] set up a module for connections, following the mysql.connector module. Also tested the app with a trial_1 table and confirmed that the sql can commit Commit statement is very important. --- trial3.py | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 trial3.py diff --git a/trial3.py b/trial3.py new file mode 100644 index 0000000..30288d1 --- /dev/null +++ b/trial3.py @@ -0,0 +1,96 @@ +import mysql.connector +import mysql +import tkinter as tki + +connection = (mysql.connector.connect + ( + host='localhost', + user='root', + #port=3306, + password='2025@Redmond', + database='trial_1')) + + +def on_button_click(): + """Function to be called when the button is clicked.""" + label.config(text="Button was clicked!") +def exit_trial(): + #print(f'welcome and goodbye {namae} ') + + #sleep(3) + exit() +def clear_label(): + label.config(text=" ") + entry_widget.delete(0, tki.END) + selected_option.set(options [0]) +def save_trial (): + name_variable = entry_widget.get() + sex = "male" + + #if name_variable == "": + #label.config(text=f' Enter the name please') + # else: + if connection.is_connected(): + #print("Successfully connected to MySQL database.") + insert_codes = f"INSERT INTO trial_1 (Name, Gender) VALUES (%s, %s)" + label.config(text=f' Bye {name_variable} , your money is coming') + cursor = connection.cursor() + cursor.execute( insert_codes, (name_variable, sex)) + connection.commit() + #sleep(2) + +# Create the main application window +root = tki.Tk() +root.title("Simple DB Example") +root.configure(bg="#FFBF00") +root.geometry("400x380") # Set window size + +#name_variable= tk.StringVar() + +#data entry +label = tki.Label(root, text= "Enter Name", fg="white", bg="#FFBF00") +label.pack(pady=10) # Add padding for better spacing + +entry_widget = tki.Entry(root, width=10,bg="white", fg="green") +entry_widget.pack(pady=10) + +#data entry 2 +label = tki.Label(root, text= "Enter gender", fg="white",bg="#FFBF00") +label.pack(pady=20) # Add padding for better spacing + +options = ["Male", "Female", "Non-binary"] + +selected_option = tki.StringVar(root) +selected_option.set(options[0]) # Set default value + +dropdown = tki.OptionMenu(root, selected_option, *options) +dropdown.pack(pady=10) + + +# Create a label widget +label = tki.Label(root, text= "Karibu", bg="#FFBF00") +label.pack(pady=20) # Add padding for better spacing + +# Create a button widget +button = tki.Button(root, text="Click Me", command=on_button_click, fg='blue') +#if on_button_click() = true + #print("welcome") +button.pack() + +button2 = tki.Button(root, text="Clear", command=clear_label, fg="blue") +#if on_button_click() = true + #print("welcome") +button2.pack() + +button1 = tki.Button(root, text="Exit", command=exit_trial, fg="blue", bg="#FFBF00") +#if on_button_click() = true + #print("welcome") +button1.pack() + +button3 = tki.Button(root, text="Save", command=save_trial, fg="blue", bg="#FFBF00") +#if on_button_click() = true + #print("welcome") +button3.pack() + +# Start the Tkinter event loop +root.mainloop() From c157ba1e1ed5ee512d19523c6f147968d30e6d87 Mon Sep 17 00:00:00 2001 From: Sri Nanak Date: Mon, 29 Sep 2025 19:08:04 -0700 Subject: [PATCH 6/7] enhanced the connection by making it possible to capture data from the option menu. --- trial3.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/trial3.py b/trial3.py index 30288d1..a8db55a 100644 --- a/trial3.py +++ b/trial3.py @@ -25,7 +25,7 @@ def clear_label(): selected_option.set(options [0]) def save_trial (): name_variable = entry_widget.get() - sex = "male" + sex = selected_option.get() #if name_variable == "": #label.config(text=f' Enter the name please') @@ -64,6 +64,7 @@ def save_trial (): selected_option.set(options[0]) # Set default value dropdown = tki.OptionMenu(root, selected_option, *options) +#selection = selected_option.get() dropdown.pack(pady=10) From b79e5a9f58b65a382de12a4275cf3d5b560982e5 Mon Sep 17 00:00:00 2001 From: Sri Nanak Date: Mon, 29 Sep 2025 20:27:03 -0700 Subject: [PATCH 7/7] success --- trial1.py | 9 +-------- trial2.py | 1 + 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/trial1.py b/trial1.py index 8002571..2c4aa54 100755 --- a/trial1.py +++ b/trial1.py @@ -1,13 +1,6 @@ import tkinter as tki from time import sleep -import dbm as db_connect - -mydb = mysql.connector.connect( - host="localhost", # Your MySQL host - user="root", # Your MySQL username - password="2025@Redmond", # Your MySQL password - database="trial_1" # The database you want to connect to - ) + def on_button_click(): """Function to be called when the button is clicked.""" diff --git a/trial2.py b/trial2.py index f23fe6f..2b99540 100644 --- a/trial2.py +++ b/trial2.py @@ -6,6 +6,7 @@ ( host='localhost', user='enos', + #port=3306, password='2025@Redmond', database='trial_1' )