I'm trying to shut down the computer when the yes button of messagebox is clicked, but my code doesn't work somehow, and I don't know where is the problem
import tkinter as tk
from tkinter import messagebox
import os
res = messagebox.askquestion("Prezentácia bez názvu.pptx", "Failed to load. Do you wish to continue? ")
def shutdown():
return os.system("shutdown /s /t 1")
def askMe():
if res == 'yes':
command=shutdown
if res == 'no':
command=shutdown
CodePudding user response:
you don`t need to use return in shutdown function, just remove the return keyword and in askMe function you can simply call shutdown function. In the last you have to call askMe function.
CodePudding user response:
yeah the code works now
from tkinter import messagebox
import os
res = messagebox.askquestion("Prezentácia bez názvu.pptx", "Failed to load. Do you wish to continue? ")
if res == 'yes':
os.system("shutdown /s /t 1")
else:
os.system("shutdown /s /t 1")