如何在一段时间后停止此程序

时间:2018-03-15 18:23:04

标签: python python-3.x exit

我刚刚开始为GCSE编写python并制作了一个名为“不按”按钮的程序,它很顺利,但最后有一部分你需要尝试点击“输入”按钮(这是不可能的)有没有人知道如何在10秒后停止它并继续该程序? (我使用来自互联网,我和朋友的所有来源,不会受到#&#39的干扰)

print("##############################")
print("DO NOT PRESS THE ENTER BUTTON!")
print("##############################")
a = input("")
b = input("Hello?")
name = input("What is your name?\n")
d = input("Aha, you know " + str(name) + " you are very anoying!")

e = input("Stop it!")
f = input("I hate you soooo much")
g = input("I am sure you don't have friends")
h = input("BECAUSE ANOYING PEOPLE DON'T HAVE FRIENDS!!!")
i = input("I just won't answer anymore")
j = input("you will get bored")
k = input(".")
l = input("..")
m = input("...")
n = input("....")
o = input(".....")
p = input("STOOOOOOPPPP!!!!!")
q = input("You know what, i will lock me in with a code HA!")

import time
import random
import sys

print("Here you go, locked...  you only have 5 tries, its between 1 and 
20, and if you fail, I WILL SHUT DOWN YOUR COMPUTER, NO ENTER BUTTON 
PRESSING THEN HAHAHA!!!\n")

#sets initial values
the_number = random.randint(1,20)
guess = int(input("Take a guess: "))
tries = 1
guesses = 5


#guessing loop


while guess != the_number:
    tries += 1
    guesses -= 1

    if guesses == 0:
        print("Computer getting shut down in,")
        print("!3!")
        time.sleep(1)
        print("!2!")
        time.sleep(1)
        print("!1!")
        time.sleep(5)
        print("Just joking haha, but this is still finished.\n\n")
        print("cOmMANd ENTER BUTTON bLOcKed!")
        time.sleep(2)
        print("#@#@#@#@#@")
        print("YOU LOSE!!")
        print("#@#@#@#@#@")
        time.sleep(2)
        sys.exit("Error message")
        break

    elif guess > the_number:
        print("Lower...")
    elif guess < the_number:
        print("Higher...")



    guess = int(input("Take a guess: "))

if guess == the_number:
    print("You guessed it! The number was", the_number)
    print("And it only took you", tries, "tries!\n")

input()

#number guesser from internet changed slightly

print("aha, i see you unlocked me, you are so vexatious...")
r = input("...")
s = input("TAKE YOUR DIRTY FINGERS OFF ME!!!")
t = input("Man you are so anoying, by the way, ure you don't even know 
what vexatious means, haha")
u = input("I will just move away, try pressing me know:")
time.sleep(4)

#Button game from internet

from tkinter import *
from random import *

def do_event(event):
    print("{},{}".format(event.x,event.y))

def jump(event):
    app.hello_b.place(relx=random(),rely=random())

class App:
    def __init__(self,master):
        frame = Frame(master)
        master.geometry("500x500")
        master.title("You will never catch me!")
        master.bind("<Button-1>",do_event)
        master.bind("<Button-1>",do_event)
        frame.pack()

        self.hello_b = Button(master,text="Enter 
        Button",command=sys.exit)
        self.hello_b.bind("<Enter>",jump)
        self.hello_b.pack()




root = Tk()

app = App(root)

root.mainloop()

#here i don't know how to end it, i want it to end after 10sec and 
#continue with that

print("ahhh you got me...")

1 个答案:

答案 0 :(得分:0)

尝试用bash编写的这个超时脚本。

#!/bin/sh
timeout 15 ./test.sh 
status=$?
if[$status -eq 124] #time out
then 
       exit 0
fi
exit $status