隨機點名2

導語:python

班級內常常須要點名回答問題,寫個腳本只爲增長一點兒樂趣,不當事兒dom

#!/usr/bin/env python
#coding=utf8
#點名腳本 
#author:CrazyWing version:0.1
import random,time,sys
from 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_name

def 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()

代碼直接複製便可運行,可自行嘗試一下
ide

相關文章
相關標籤/搜索