Python Forum

Full Version: Returning a message when SQL server is unavailable
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm using pymysql and I have a login script like the one bellow:
How can I raise a message to user when the sql server is unavailable?

import pymysql
import tkinter as tk


def submitact():
    user = Username.get()
    passw = password.get()

    print(f"The name entered by you is {user} {passw}")

    logintodb(user, passw)


def logintodb(user, passw):

    # If password is enetered by the
    # user
    global db
    if passw:
        db = pymysql.connect(host="localhost",
                             user=user,
                             password=passw,
                             db="prices")
        cursor = db.cursor()

    # If no password is enetered by the
    # user
    else:
        print("Erorr", "No password")

    try:
        print("Query Executed successfully")

    except:
        db.rollback()
        print("Error occurred")



    finally:
        db.rollback()
        print("Error")



root = tk.Tk()
root.geometry("300x300")
root.title("Login Page")

# Defining the first row
lblfrstrow = tk.Label(root, text="Username -", )
lblfrstrow.place(x=50, y=20)

Username = tk.Entry(root, width=35)
Username.place(x=150, y=20, width=100)

lblsecrow = tk.Label(root, text="Password -")
lblsecrow.place(x=50, y=50)

password = tk.Entry(root, width=35)
password.place(x=150, y=50, width=100)

submitbtn = tk.Button(root, text="Login",
                      bg='blue', command=submitact)
submitbtn.place(x=150, y=135, width=55)

root.mainloop()
Display a message in a popup dialog window? Have a status display on the bottom of the main window? Use a text box to display logger information?

How do you want it to work?
In a pop-up window!
Thanks!