导语:

班级内经常需要点名回答问题,写个脚本只为增加一点儿乐趣,不当事儿

#!/usr/bin/env python#coding=utf8#点名脚本 #author:CrazyWing version:0.1import random,time,sysfrom Tkinter import *name=["赵建建","郭耀","陈世铎","郑军善","卢国祥","赵一凡","刘勇","赵坤","张武松","贺洋伟","牛婷婷","戴钦远","胡旭龙","孙志鹏","庄曜","石宇飞","李政","杨森","张学","王晓轩","刘印","陈阳","侯子","张会淼","赵宏"]length=len(name)root=Tk()root.title("无名")root.geometry('600x450')root.resizable(width=True,height=True)l1=Label(root,text="Who Are You!",font=("Arial",35),width=30,height=3)def sui():    num=random.randint(0,length-1)    dis_name=name[num]    return dis_namedef suiji():     t.delete(1.0, 'end')     t.insert('end', sui())     t.after(1000, suiji)      #这是文本切换的地方,1000毫秒执行一次后面的函数。    t=Text(root,bg='red',font=("Arial",25),width=6,height=1)    l2=Label(root,text="Come On!",font=("Arial",35),width=20,height=3)def new():    root1 = Tk()    root1.title("无名")    root1.geometry('600x450')    root1.resizable(width=True,height=True)    aa=sui()    l3=Label(root1,text="It's You!",font=("Arial",35),width=30,height=3)    l4 = Label(root1,text=aa,font=("Arial",25),width=6,height=1,bg='red')    l5=Label(root1,text="Come On Baby!",font=("Arial",35),width=30,height=3)    l3.pack()    l4.pack()    l5.pack()    root.destroy()    root1.mainloop()    button = Button(root, text="STOP", command=new)    l1.pack()    t.pack()    l2.pack()    button.pack()suiji()root.mainloop()

代码直接复制即可运行,可自行尝试一下