Python3 + pywin32 getting user-defined ODBC data source _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.