Under Windows, get a user-defined data source by reading the registry
[Python]
#-*-Coding:utf-8-*-
# Get 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\\odbc. Ini\\odbc Data Sources ', 0, Win32con. key_all_access)
#print (Key)
#print (Win32API. RegQueryValue (Key, "))
#print (' Number of subkeys returned, number of item values, and last modified 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 ()
http://www.bkjia.com/PHPjc/477920.html www.bkjia.com true http://www.bkjia.com/PHPjc/477920.html techarticle windows, obtaining a user-defined data source by reading the registry [Python] #-*-coding:utf-8-*-# Get ODBC data source list from Tkinter Import * from Tkinter import TT K Import W ...