python3+pywin32 Obtain user-defined ODBC data source_PHP tutorial

WBOY
Release: 2016-07-14 10:06:43
Original
1146 people have browsed it

Under Windows, obtain user-defined data sources 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('Return the number of sub-items, the 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()

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477920.htmlTechArticleUnder windows, obtain user-defined data sources by reading the registry [python] # -*- coding: UTF -8 -*- # Get the ODBC data source list from tkinter import * from tkinter import ttk import w...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template