tkinter messagebox which turns your computer off

martin

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

Gautam Jangid

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Change time after which locked computer turns off display

Computer turns off unexpectedly

computer turns on when plugged in then turns off immediately

Computer turns itself on after any off mode

Computer turns off unexpectedly (new battery)

My computer turns off after 0.5 seconds

Computer makes hissing noise, turns off after few seconds

What happens to the content of RAM when a computer turns off?

My computer turns off unexpectedly when left idle (light to no load)

CKEDITOR - Which plugin or settings turns ON/OFF CKEDITOR formatting marks?

How much power do video cards use after Windows turns your display off?

Computer turns on and then off after a few seconds when front panel is connected, but works normally without it

Computer turns off after 30s of booting Windows 10 or Linux

New computer turns off after few minutes of using it. Powers back on. PSU?

After being unplugged when I turn on computer it quickly turns off and back on again

Keyboard randomly turns off

HDD randomly turns off and then on

How to handle MySQL CommunactionException which occurs when database turns off when application is running

Computer AI turns in a UIViewController

computer turns on then goes in to standby

Computer turns on but no signal in monitor

Monitor turns on, emits sound, then lcd turns off

issue with tkinter messagebox

Tkinter MessageBox gives error

Tkinter messagebox running twice

change size of tkinter messagebox

Copying from Messagebox with Tkinter

Make a tkinter messagebox optional

Wireless keyboard and mouse Dell QWERTY older type keyboard. Quarter moon sign Stopped working as a sleepbutton it now turns off the computer