1

I have some code that creates a lock screen using python that deletes the task bar and stops them leaving. However when they get the password right it does not make the task bar come back. The command works in cmd but it does not work in python.

Here is the code:

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()
Bellerofont
  • 1,081
  • 18
  • 17
  • 16
  • after clearing some errors in your code, i tested it and it seems to be working fine for me; the os.system is launching explorer properly with that command. Can you check specifically by launching the command in new window with python if it gets executed or not. – iamnotgoogle Jan 29 '17 at 12:38
  • I tested just the cod to get the task bar back alone in a new python window but it still did not work. All it did was open cmd and then it left cmd open without doing anything. – Alex Andrew Jan 29 '17 at 12:44
  • Can you test it with python 2.7? i have python 2.7 enabled by default. (another thing this is a weird behavior from the program considering the taskkill command is running and this isn't, either both should work or both shouldn't) – iamnotgoogle Jan 29 '17 at 12:48

1 Answers1

0

It worked for me after clean your code:

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()
Tito
  • 366
  • 4
  • 9
  • 3
    Your answer would be better if you took the time to explain whatever critical changes you made. Otherwise the reader has to compare your solution to the original solution line-by-line and character-by-character. – Bryan Oakley Jan 29 '17 at 14:59