简体   繁体   English

Windows上的Python,关闭并截图

[英]Python on windows, shutting down and taking a screenshot

I have the following two quesions: 我有以下两个问题:

1 I want to be able to shutdown windows xp from python code. 1我希望能够从python代码关闭Windows XP。 I am able to do that by running the following code in the python console: 我可以通过在python控制台中运行以下代码来做到这一点:

import os

os.system("shutdown -s -f")

But, if i put the same code in a .py file and try to execute it,it does not work. 但是,如果我将相同的代码放在.py文件中并尝试执行它,则它将不起作用。 I get the help prompt for the shutdown command.Any way to fix this ? 我会收到有关shutdown命令的帮助提示。是否可以解决此问题?

2 Is there any way i can take a screenshot of the current screen using python on windows ? 2有什么办法可以在Windows上使用python截取当前屏幕的屏幕截图?

Thank You 谢谢

There's some code to shutdown windows in this message from the python-win32 list. 在python-win32列表中的此消息中 ,有一些代码可以关闭Windows。

You can take a screen shot using PIL's ImageGrab module. 您可以使用PIL的ImageGrab模块进行屏幕截图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM