Python教程

python与C互相调用微全

本文主要是介绍python与C互相调用微全,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
# C调用python. search(Calling Python Functions From C PyObject Py_XDECREF Py_XINCREF).
# 
# SetWindowsHookEx,回调函数用Python写: https://www.cnblogs.com/funwithwords/p/15669613.html ctypes
# 用SetConsoleTextAttribute设置文本颜色: https://www.cnblogs.com/funwithwords/p/15670028.html ctypes
# 
# pip install pywin32
# import win32clipboard as w
# import win32con
# def get_text(): w.OpenClipboard(); s=w.GetClipboardData(win32con.CF_UNICODETEXT); w.CloseClipboard()
# win32api.MessageBox(0,"msgbox", "title")
# 
# pip install pyperclip 还有个wheel叫clipboard.
# import pyperclip
# pyperclip.copy('The text to be copied to the clipboard.')
# pyperclip.paste()
# 
# D:\Python39\Lib\site-packages\pythonwin\Pythonwin.exe 默认没有加入PATH.
# D:\Python39\Lib\site-packages\pythonwin\pywin\Demos\*.py 大部分需要先运行pywin,再在pywin里运行.py
# 
# >>> help(pywin)
# PACKAGE CONTENTS
#     debugger (package)
#     dialogs (package)
#     docking (package)
#     framework (package)
#     idle (package)
#     mfc (package)
#     scintilla (package)
#     tools (package)
#
# First demo - use the built-in to Pythonwin "Tab Stop" dialog, but
# customise it heavily.
class TestDialog(dialog.Dialog):
    def __init__(self, modal=1):
        dialog.Dialog.__init__(self, IDD_SET_TABSTOPS)
        self.counter = 0
        if modal:
            self.DoModal()
        else:
            self.CreateWindow() # 菜鸟MFC程序员都不知道无模式对话框呢
    def OnInitDialog(self):
        self.SetWindowText("Used to be Tab Stops!")
        self.edit = self.GetDlgItem(IDC_EDIT_TABS)  # the text box.
        self.edit.SetWindowText("Test")
    def OnDestroy(self, msg):
        del self.edit
        del self.counter
        
import pywin.dialogs.list
print(pywin.dialogs.list.SelectFromList('Select fruit', ['apple', 'grape', 'orange']))
这篇关于python与C互相调用微全的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!