首先来一段简单一点的,额,要不就先来看看time.sleep()?python
import time count = 1 tag = True name = 'script' pwd = '123' while tag: if count == 4: print('Too many time!') break username = input('Please enter your username:').strip() password = input('Please enter your password:') if not username: print('again!') continue elif not password: print('gaain') continue if username == name and password == pwd: print('Login successfully!') while tag: user_cmd = input('Please enter you order:'.strip()) if user_cmd == 'q': tag = False break print('You type in thr command %s' % user_cmd) else: print('The user name or password you entered is incorrect,please re-enter.') print('You only have %s chance' % (3-count)) count += 1 print(['5秒后结束,再见!']) time.sleep(5) # 也就是上面所述,让程序过了5秒后再结束
那么问题来了,为何后面要来一个5秒后结束,那为何不整一个过了一秒打印一次,最后到了5秒后结束呢?windows
哈哈,很差意思,我说我不会写,(我以为这是一个值得让人思考的问题,也就没有写上去了,由于有了想法才有动力)app
那咱们来作一个简单的钟表吧ide
import threading,time global t def sayHello(): print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))) t = threading.Timer(1.0,sayHello) t.start() sayHello()
有不少的缺陷在里面,可是也是个不错的问题,值得让人去深究oop
而后我想到用Tkinter去实现时钟ui
import Tkinter,sys,time root=Tkinter.Tk() root.minsize(500, 500) Label1=Tkinter.Label(text=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))) Label1.pack() def trickit(): currentTime=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())) Label1.config(text=currentTime) root.update() Label1.after(1000, trickit) Label1.after(1000, trickit) root.mainloop()
经过Tkinter制做windows窗口界面,而后去实现一个简单的倒计时功能spa
from Tkinter import * import time import tkMessageBox class App: def __init__(self,master): frame = Frame(master) frame.pack() self.entryWidget = Entry(frame) self.entryWidget["width"] = 15 self.entryWidget.pack(side=LEFT) self.hi_there = Button(frame, text="Start", command=self.start) self.hi_there.pack(side=LEFT) self.button = Button(frame, text="QUIT", fg="red", command=frame.quit) self.button.pack(side=LEFT) def start(self): text = self.entryWidget.get().strip() if text != "": num = int(text) self.countDown(num) def countDown(self,seconds): lbl1.config(bg='yellow') lbl1.config(height=3, font=('times', 20, 'bold')) for k in range(seconds, 0, -1): lbl1["text"] = k root.update() time.sleep(1) lbl1.config(bg='red') lbl1.config(fg='white') lbl1["text"] = "Time up!" tkMessageBox.showinfo("Time up!","Time up!") def GetSource(): get_window = Tkinter.Toplevel(root) get_window.title('Source File?') Tkinter.Entry(get_window, width=30, textvariable=source).pack() Tkinter.Button(get_window, text="Change", command=lambda: update_specs()).pack() root = Tk() root.title("Countdown") lbl1 = Label() lbl1.pack(fill=BOTH, expand=1) app = App(root) root.mainloop() #该代码片断来自于: http://www.sharejs.com/codes/python/7826
我那时候就出了不少问题,可是具体在哪出的,我也不得而知了
下面是包的问题.net
转载:http://www.javashuo.com/article/p-xlmtcrtp-ga.htmlcode
具体是个什么状况,我想仍是得具体分析了,blog