After writing the script below(which works perfectly), I open the cmd.exe windows prompt and type the following
pyinstaller -F --windowed myscript.py
which gives me a file called "myscript.exe".
The problem is when I open the executable and press the button, nothing happens. I think there is a problem with this line:
check_output("shutdown -s -t 60", shell=True)
Even though the script works "as a script", it doesn't work as an executable.
I've tried other syntax like
os.system("shutdown -s -t 60")
but they don't seem to work.
from tkinter import *
from subprocess import check_output,CalledProcessError
class main_gui:
def __init__(self,master):
self.master=master
master.geometry("250x100")
self.button1=Button(self.master,
text="Press me",
font="Times 10 bold",
command=self.shutdown)
self.button1.pack()
def shutdown(self):
try:
check_output("shutdown -s -t 60", shell=True)
print("Computer will shutdown in 60 seconds")
except CalledProcessError:
print("Already pressed")
root = Tk()
my_gui = main_gui(root)
root.mainloop()
What can I do?