46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
import tkinter
|
|
import pyodbc
|
|
|
|
sql_server_ver = "Not Available"
|
|
|
|
root = tkinter.Tk()
|
|
root.geometry("600x400")
|
|
root.title("Sample Python GUI App")
|
|
|
|
label_hello_world = tkinter.Label(root, text=str(sql_server_ver), fg="red")
|
|
|
|
def sql_server_version():
|
|
|
|
try:
|
|
connection = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=.;DATABASE=SampleDB;Trusted_Connection=yes')
|
|
|
|
cursor = connection.cursor()
|
|
|
|
cursor.execute("select @@VERSION as version")
|
|
|
|
while 1:
|
|
row = cursor.fetchone()
|
|
if not row:
|
|
break
|
|
sql_server_ver = row.version
|
|
|
|
cursor.close()
|
|
connection.close()
|
|
|
|
except pyodbc.Error as ex:
|
|
print()
|
|
print("exception: ",ex)
|
|
cursor.close()
|
|
connection.close()
|
|
print()
|
|
exit()
|
|
|
|
label_hello_world.config(text=str(sql_server_ver))
|
|
label_hello_world.pack()
|
|
|
|
btn_sql_server_version = tkinter.Button(root, command=sql_server_version, text="Retrieve SQL Server Version")
|
|
btn_sql_server_version.pack(side=tkinter.TOP, pady=50)
|
|
|
|
|
|
root.mainloop()
|