Python connectivity with Oracle Database user SYSDBA in tkintor

Create login window by using python Connectivity with Oracle Database user and password in GUI

from tkinter import *
from functools import partial
from tkinter import filedialog

import cx_Oracle

def validateLogin(username, password, tnsstring,CheckVar1):
    #print("username entered :", username.get())
    #print("password entered :", tnsstring.get())
    v_username=username.get()
    v_password=password.get()
    v_tnsentry=tnsstring.get()
    var_checkbox = CheckVar1.get()
    #print(var_checkbox)
 
    
    if var_checkbox == 0:
       try:
           #conn = cx_Oracle.connect(user=r'hr', password='hr', dsn='pdb1')
           conn = cx_Oracle.connect(user=username.get(), password=password.get(), dsn=tnsstring.get())
           messagebox.showinfo(title="Info", message="Connection Successful")
       except cx_Oracle.DatabaseError as e:
              error, = e.args
              print("Error Code:", error.code)
              print("Error Message:", error.message)
              messagebox.showerror(title="Error", message=error.message)
    elif var_checkbox==1:
        try:
             # print ("sysdba")
             # conn = cx_Oracle.connect(user=r'sys', password='laks', dsn='pdb1',mode = cx_Oracle.SYSDBA)
             conn = cx_Oracle.connect(user=username.get(), password=password.get(), dsn=tnsstring.get(),mode = cx_Oracle.SYSDBA)
             messagebox.showinfo(title="Info", message="Connection Successful")
        except cx_Oracle.DatabaseError as e:
            error, = e.args
            print("Error Code:", error.code)
            print("Error Message:", error.message)
            messagebox.showerror(title="Error", message=error.message)
    
   
#windows
tkWindow = Tk()  
tkWindow.geometry('500x500')  
tkWindow.title('Import/Export Utility')
#username label and text entry box
usernameLabel = Label(tkWindow, text=r"User Name").grid(row=5, column=5, padx=2, pady=2)
username = StringVar()
usernameEntry = Entry(tkWindow, textvariable=username).grid(row=5, column=6, padx=2, pady=2)

CheckVar1 = IntVar()
C1 = Checkbutton(tkWindow, text = "SYSDBA", variable = CheckVar1,onvalue = 1, offvalue = 0)
C1.grid(row=5,column=7, padx=2, pady=2)

#password label and password entry box
passwordLabel = Label(tkWindow,text="Password").grid(row=6, column=5, padx=2, pady=2)  
password = StringVar()
passwordEntry = Entry(tkWindow, textvariable=password, show='*').grid(row=6, column=6, padx=2, pady=2)  

#tns names label and tnsnames entry box
tnslabel = Label(tkWindow,text="Tnsnames Entry").grid(row=7, column=5, padx=2, pady=2)  
tnsstring = StringVar()
tnsEntry = Entry(tkWindow, textvariable=tnsstring).grid(row=7, column=6, padx=2, pady=2)  

validateLogin = partial(validateLogin, username, password, tnsstring,CheckVar1)

#login button
loginButton = Button(tkWindow, text="Login", command=validateLogin).grid(row=8, column=6, padx=10, pady=20)  
  
tkWindow.mainloop()

Output:

Example of showing connection with Oracle User with Python tkintor GUI tool

Successfully Make Connection from Python GUI window to Oracle User

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.