0
我一直在試圖編寫一個python程序來自動關閉我的電腦。通知消息箱模塊使用類似於TutorialPoint中的tkinter代碼。彈出窗口將顯示是/否選項。 與當前的代碼,只有當我按「否」按鈕,系統將關閉。Python做的動作沒有彈出響應
所以相反,它應該自動啓動關機過程,而不需要點擊任何東西。同時,如果我點擊「是」,那麼關機過程應該停止。
這是代碼。我如何做到這一點?
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()
感謝。我已經有一個CloseApps()和ShutDown()函數,但我的問題是關機應該自動啓動,但如果我想中止,我應該仍然可以... – Naveen
終端命令'shutdown/a'可以被用來中止關機。請參閱https://stackoverflow.com/questions/2358929/prevent-windows-7-shutdown – RottenCandy