0
私はコンピュータを自動的にシャットダウンするためのPythonプログラムを作成しようとしていました。 Notification Messageboxモジュールは、TutorialPointのようなtkinterコードを使用します。ポップアップには[はい/いいえ]オプションが表示されます。 "No"ボタンを押すと、現在のコードで が表示され、システムがシャットダウンします。ポップアップレスレスのアクションをPythonが行う
代わりに、何もクリックしないでシャットダウンプロセスを自動的に開始するはずです。また、「はい」をクリックすると、シャットダウンプロセスが停止するはずです。
これはコードです。どのように私はこれを達成するのですか?
closeApps()
については
import MessageBox
def PopUp(Title, Msg, Type='Info'):
Title = str(Title)
Msg = str(Msg)
root = tk.Tk()
root.withdraw()
if Type == "Question":
response = MessageBox.askquestion(Title, Msg)
print("question", response)
return response
elif Type == "TryAgain":
response = MessageBox.askretrycancel(Title, Msg)
print("try again", response)
return response
else:
print("Incorrect Type selected.")
response = MessageBox.showinfo(Title, Msg)
print("info", response)
return response
def main():
CurrentTime = int(time.strftime('%H'))
if CurrentTime > 22 or CurrentTime < 5:
msg = ("The Time is %s hours. Abort Automatic Shutdown?" % CurrentTime)
resp1 = Notification.PopUp("Auto Shut Down", msg, Type="Question")
print('Response from Notification is %s' % resp1)
if resp1 == 'no':
closeApps()
shutDown()
else:
print('ShutDown abortered by user.')
if __name__ == '__main__':
main()
ありがとう:
は
shutDown()
として、あなたは単にターミナルコマンドを与えることos
を使用する必要があります。私はすでにCloseApps()とShutDown()の両方の機能を持っていますが、私の問題はシャットダウンが自動的に開始するはずですが、中止したい場合でも私はまだできるはずです... – Naveen端末コマンド 'shutdown/a'シャットダウンを中止するために使用します。 https://stackoverflow.com/questions/2358929/prevent-windows-7-shutdownを参照してください。 – RottenCandy