Python3 + pywin32 get the user-defined ODBC data source. In windows, get the user-defined data source by reading the registry [python] #-*-coding: UTF-8-*-# get the ODBC data source list fromtkinterimport * fromtkinterimportttkimportw in windows, obtain user-defined data sources by reading the registry
[Python]
#-*-Coding: UTF-8 -*-
# Getting the ODBC data Source list
From tkinter import *
From tkinter import ttk
Import win32api, win32con
Def GetODBCdsn ():
Key = win32api. RegOpenKey (win32con. HKEY_CURRENT_USER,
'Software \ ODBC. INI \ ODBC Data Sources ', 0, win32con. KEY_ALL_ACCESS)
# Print (key)
# Print (win32api. RegQueryValue (key ,''))
# Print ('number of items returned, number of item values, and the last modification time', win32api. RegQueryInfoKey (key ))
Subitem, item, opdate = win32api. RegQueryInfoKey (key)
Dsnlist = []
For I in range (item ):
Print ('---', win32api. RegEnumValue (key, I ))
DsnName, dsnObject, dsnType = win32api. RegEnumValue (key, I)
Dsnlist. append (dsnName)
# Print (dir (win32api ))
Win32api. RegCloseKey (key)
Return dsnlist
Class MFrame (Frame ):
Def _ init _ (self, master = None, cnf = {}, ** kw ):
Self. master = master
Self. master. title ('get user-defined data source ')
Self. combo = ttk. Combobox (self. master)
Self. combo. config (state = "readonly ")
Self. combo. pack (side = TOP, fill = 'x', expand = False)
Self. combo. update_idletasks ()
Comlist = GetODBCdsn ()
Self. combo ['values'] = comlist
Def test ():
GetODBCdsn ()
Def main ():
Root = Tk ()
Mf = MFrame (root)
Root. mainloop ()
If _ name __= = "_ main __":
# Test ()
Main ()
Plugin [python] #-*-coding: UTF-8-*-# get ODBC data source list from tkinter import * from tkinter import ttk import w...