1

I am currently working on a project where I have to build an app in python. I decided to use the tkinter framework but right now I am having some trouble on how to add a specific feature. So this app is connected to a database, and while the database is online the program opens in about 1 or 2 seconds, but if it's not the case the program takes a while to open but until it opens it gives no sign that is opening or trying to connect to that database. Here's a part of my code:

try:
    db = MySQLdb.connect(
        host="hostname",
        port=port,
        user="username",
        password="password",
        database="database_name"
    )
except MySQLdb.Error as e:
    warning_box=ctypes.windll.user32.MessageBoxW(0, "Looks like there's been an error while trying to connect to the database please try again later", "Error", MB_OK | ICON_STOP)

    if warning_box == 1:
        exit()

I added this try except cicle in order to give me that message after it fails to connect to the database, although, like I said, it takes a while to show this error so I wanted to add something like this: progress-bar

code_dev
  • 95
  • 8
  • 2
    You can start a new thread that runs `MySQLdb.connect...` in the background. Then show the dialog until the connect thread is finished. – 001 Mar 16 '23 at 11:42
  • Please post a [minimal-reproducible-example](https://stackoverflow.com/help/minimal-reproducible-example). – Ben the Coder Mar 16 '23 at 14:24
  • See [this answer](https://stackoverflow.com/a/74989468/1186624). – relent95 Mar 20 '23 at 01:57

0 Answers0