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 diff --git a/trial1.py b/trial1.py index 3b21281..2c4aa54 100755 --- a/trial1.py +++ b/trial1.py @@ -16,8 +16,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() diff --git a/trial2.py b/trial2.py new file mode 100644 index 0000000..2b99540 --- /dev/null +++ b/trial2.py @@ -0,0 +1,30 @@ +import mysql.connector +import mysql + +try: + connection = (mysql.connector.connect + ( + host='localhost', + user='enos', + #port=3306, + 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 trial_1") + 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 diff --git a/trial3.py b/trial3.py new file mode 100644 index 0000000..a8db55a --- /dev/null +++ b/trial3.py @@ -0,0 +1,97 @@ +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 = selected_option.get() + + #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) +#selection = selected_option.get() +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()