我尝试使用以下代码在 Windows 上打印文档
import os
import sys
os.startfile(r"D:/DEV/Python-Diverses/os/testb.png", "print")
但是什么也没发生 - 程序运行但没有打印。
当我用
打开文件时os.startfile(r"D:/DEV/Python-Diverses/os/testb.png")
它在图像查看器程序(Windows图像查看器)中打开。
有什么办法无法打印吗?
我也有同样的问题。我检查了一些文档,发现了以下解决方案:在 os.startfile 之后添加 time.sleep 。
导入操作系统
导入系统
导入时间
os.startfile(r"D:/DEV/Python-Diverses/os/testb.png", "print")
时间.睡眠(5)
这对我有用。 也许它也适合你。
P.S 我从以下页面得到了这个解决方案: https://www.geeksforgeeks.org/how-to-print-all-files-within-a-directory-using-python/