繁体   English   中英

python 3.4 - os.system不执行命令

[英]python 3.4 - os.system not executing the command

我有一些代码使用python创建一个锁定屏幕,删除任务栏并阻止他们离开。 但是,当他们获得正确的密码时,它不会使任务栏返回。 该命令在cmd中工作,但在python中不起作用。

这是代码:

import os
from tkinter import*
import time
run = input("Do you want to lock your computer? ")
if run == "yes":
    a=Tk()
    a.overridedirect(1)
    w, h = a.winfo_screenwidth(), a.winfo_screenheight()
    a.geometry("%dx%d+0+0" % (w, h))
    os.system('taskkill /f /im  explorer.exe')
    a.attributes("-topmost", True)
    L1 = Label(a, text="Please enter the password to continue: ")
    L1.pack( side =TOP)
    Ebox = Entry(a, bd =5)
    Ebox.pack(side =TOP)
    Ebox.config(show="*");

    def check():
    if Ebox.get() == "password":
        time.sleep(0.3)
        os.system('powershell -command "Invoke-item c:\windows/explorer.exe"') # This line does not execute the command
        a.destroy()


    b = Button(a, text="submit", command=check )
    b.pack(side=TOP)
    a.mainloop()

清理完代码后,它对我有用:

import os
from tkinter import*
import time

run = input("Do you want to lock your computer? ")
if run == "yes":
    a=Tk()
    a.overrideredirect(1)
    w, h = a.winfo_screenwidth(), a.winfo_screenheight()
    a.geometry("%dx%d+0+0" % (w, h))
    os.system('taskkill /f /im  explorer.exe')
    a.attributes("-topmost", True)
    L1 = Label(a, text="Please enter the password to continue: ")
    L1.pack( side =TOP)
    Ebox = Entry(a, bd =5)
    Ebox.pack(side =TOP)
    Ebox.config(show="*");

    def check():
      print("Hello")
      typed=Ebox.get()
      print(typed)
      if typed == "password":
        time.sleep(0.3)
        print("Ok")
        os.system('powershell -command "invoke-item c:\windows/explorer.exe"') # this line does not execute the command
        a.destroy()

    b = Button(a, text="submit", command=check)
    b.pack(side=TOP)

    a.mainloop()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM