【发布时间】:2019-01-02 22:33:05
【问题描述】:
写完下面的脚本(完美运行)后,我打开cmd.exe windows 提示符并输入以下内容
pyinstaller -F --windowed myscript.py
这给了我一个名为“myscript.exe”的文件。
问题是当我打开可执行文件并按下按钮时,没有任何反应。我认为这行有问题:
check_output("shutdown -s -t 60", shell=True)
即使脚本“作为脚本”工作,它也不能作为可执行文件工作。
我尝试过其他语法,例如
os.system("shutdown -s -t 60")
但它们似乎不起作用。
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()
我能做什么?
【问题讨论】:
标签: python python-3.x windows executable pyinstaller