Nov-27-2022, 11:22 AM
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?
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()