pywin32

Python: copying from clipboard using tkinter without displaying window

允我心安 提交于 2019-11-28 01:19:32
问题 Running Python 3.4 on Windows 7. I need to copy what's stored in the clipboard to a variable in my python program. I've seen on Stack Overflow that that can be done either with pywin32 or tkinter. Since tkinter is part of the python standard library, I decided that that was the better of the two since the user won't have to install an external module. Here's the code for getting the clipboard data in tkinter: import tkinter number = tkinter.Tk().clipboard_get() This works fine except a blank

python3 ctype CreateWindowEx simple example

心已入冬 提交于 2019-11-28 00:54:41
问题 I have googled for some time but could not find simple example of python3 ctypes and Win32 API for creating and showing window. Please point me to good link or show code here. Thanks in advance! 回答1: This is most easy to do with the win32gui module and its friends, win32api and win32con. There's no need to write your own ctypes wrappers to the Windows API. The simplest Petzold style app comes out something like this: import win32api, win32con, win32gui class MyWindow: def __init__(self):

How to catch printer event in python

大兔子大兔子 提交于 2019-11-27 23:18:41
I want to catch the signal when the printer started to print. That would be fine if you tell me how to get the path of document that will print. pywin32print looks like useful but I don't know how to use. To be notified of new print jobs, you can use FindFirstPrinterChangeNotification , FindNextPrinterChangeNotification , and a wait function from kernel32 such as WaitForSingleObject . Here's an example to set a filter that waits for a new print job on the local print server. There's much more work to be done if you want the JOB_NOTIFY_FIELD_DOCUMENT value out of a PRINTER_NOTIFY_INFO_DATA

Unprotect an Excel file programmatically

岁酱吖の 提交于 2019-11-27 23:05:39
问题 We're getting an Excel file from a client that has open protection and Write Reserve protection turned on. I want to remove the protection so I can open the Excel file with the python xlrd module. I've installed the pywin32 package to access the Excel file through COM, and I can open it with my program supplying the two passwords, save, and close the file with no errors. I'm using Unprotect commands as described in MSDN network, and they're not failing, but they're also not removing the

what SendMessage to use to send keys directly to another window?

最后都变了- 提交于 2019-11-27 19:04:38
问题 I'm trying to use SendMessage to send keyboard input to another window. I know the drawbacks, but I have to do it since I have to send several keys and I can't guarantee that the window will have focus - so this has to work when the window doesnt have focus. I'm testing it by trying to send keys to a notepad window. I've tried the following variations, and none have worked: def post_keys1(hwnd): win32api.SendMessage( hwnd, win32con.WM_KEYDOWN, ord('A'), 0 + (0 << 8) + (ord('A') << 16) + (0 <<

Use Python to extract ListView items from another application

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 18:56:50
问题 I have an application with a ListView ('SysListView32') control, from which I would like to extract data. The control has 4 columns, only textual data. I have been playing around the following lines (found online somewhere): VALUE_LENGTH = 256 bufferlength_int=struct.pack('i', VALUE_LENGTH) count = win32gui.SendMessage(TargetHwnd, commctrl.LVM_GETITEMCOUNT, 0, 0) for ItemIndex in range(count): valuebuffer = array.array('c',bufferlength_int + " " * (VALUE_LENGTH - len(bufferlength_int)))

win32com import error python 3.4 [duplicate]

喜夏-厌秋 提交于 2019-11-27 17:58:50
问题 This question already has an answer here: import win32api error in Python 2.6 11 answers I just installed python 3.4 64bit and tried to install win32com. I have downloaded pywin32-218.win-amd64-py3.4.exe and ran it without any problem. pip freeze reports pywin32==218. However, when I try to import win32com.client I get following error: Traceback (most recent call last): File "<pyshell#1>", line 1, in <module> import win32com.client File "C:\program files\Python34\lib\site-packages\win32com\_

How to install pywin32 module in windows 7 [duplicate]

故事扮演 提交于 2019-11-27 17:58:28
This question already has an answer here: ImportError: no module named win32api 4 answers I am trying to install pywin32. I downloaded it from sourceforge.net. When I run setup.py install it shows "Unable to find vcvarsall.bat". I Googled about it and found that I have to install MinGW and set path then run python setup.py build --compiler=mingw32 but it's showing Can't find a version in Windows.h Can anybody help? (I have a trial version of Visual Studio 2010 Ultimate installed and MinGW C and C++ compiler installed. Operating system: Windows 7.) Can anybody tell me a source from where I can

Write image to Windows clipboard in python with PIL and win32clipboard?

泄露秘密 提交于 2019-11-27 15:45:50
I'm trying to open an image file and copy the image to the Windows clipboard. Is there a way to fix this: import win32clipboard from PIL import Image def send_to_clipboard(clip_type, data): win32clipboard.OpenClipboard() win32clipboard.EmptyClipboard() win32clipboard.SetClipboardData(clip_type, data) win32clipboard.CloseClipboard() clip_type = win32clipboard.CF_BITMAP filepath = 'c:\\temp\\image.jpg' im = Image.open(filepath) data = im.tobitmap() # fails with valueerror: not a bitmap # data = im.tostring() runs, but receiving programs can't read the results send_to_clipboard(clip_type, data) I

Error installing and running pywin32 2.7

。_饼干妹妹 提交于 2019-11-27 14:40:01
问题 I am coming up with a couple errors after installing: pywin32-217.win32-py2.7 I have recently upgraded ArcGIS to 10.1 and it uses Python 2.7 (as opposed to 2.6 that came with ArcGIS 10.0) When I run the installer on a Windows 7 64 bit, it installs, but throws the following message: close failed in file object destructor: sys.excepthook is missing lost sys.stderr I had a simple python script to print to a printer from a folder containing .pdf files which worked before my upgrade import arcpy,