2017-09-10 1 views
0

나는 파이썬 프로그램을 작성하여 내 컴퓨터를 자동으로 종료하려고 시도했다. Notification Messagebox 모듈은 TutorialPoint과 같은 tkinter 코드를 사용합니다. 팝업에는 예/아니오 옵션이 표시됩니다. 현재 코드가 이고 "No"버튼을 누르면 시스템이 종료됩니다.팝업 반응이없는 파이썬 do action

대신, 아무 것도 클릭하지 않아도 자동으로 종료 프로세스가 시작됩니다. 그 때 "예"를 클릭하면 종료 프로세스가 중지됩니다.

이것은 코드입니다. 어떻게해야합니까?

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() 

답변

0

closeApps()를 들어, psutil 모듈,

import psutil 
for process in psutil.process_iter(): 
    if process.name()=="Application.exe": 
     process.kill() 

psutil.process_iter()

가 실행중인 모든 프로세스의 목록을 제공을 사용할 수 있습니다.

참고 : "Application.exe"을 닫을 응용 프로그램의 이름으로 바꾸십시오.

import os 
os.system("shutdown /s") 
+0

감사 :

shutDown()에 관해서는, 당신은 단순히 터미널 명령을주고 os을 사용해야합니다. 나는 CloseApps()와 ShutDown() 둘 다에 이미 함수를 가지고 있지만 내 문제는 Shutdown이 자동으로 시작되어야한다는 것이지만, 중단하고 싶다면 여전히해야한다. – Naveen

+0

터미널 명령'shutdown/a'은 다음과 같이 할 수있다. 종료를 중단하는 데 사용됩니다. https://stackoverflow.com/questions/2358929/prevent-windows-7-shutdown을 참조하십시오. – RottenCandy