[Python]实现简易点名器 您所在的位置:网站首页 python随机点名系统设计 [Python]实现简易点名器

[Python]实现简易点名器

#[Python]实现简易点名器| 来源: 网络整理| 查看: 265

点名器

最近在学习Python, 做了一个简易的点名器, 使用Excel导入点名名单

使用到的库:

1.xlrd(用于读取Excel表)

2.random(用于获取随机数)

3.tkinter(用于绘制界面)

import random import tkinter as tk from tkinter import messagebox import xlrd window=tk.Tk() window.title('Call Name') window.geometry('300x400') excel_path = tk.Entry( window, width=50 ) excel_path.pack() x_values = [] def load_excel(): try: reader = xlrd.open_workbook(excel_path.get()) sheet = reader.sheet_by_index(0) global x_values x_values = sheet.col_values(0) except: tk.messagebox.showwarning(title='Warning', message='Read excel Error!') btn_read_name=tk.Button( window, text='load', width=15, height=2, command=load_excel ) btn_read_name.pack(pady=30) var=tk.StringVar() lab_show=tk.Label( window, textvariable=var, bg='black', fg='white', font=('Arial',12), width=15, height=2 ) lab_show.pack(pady=30) def rand_get_name(): var.set('') var.set(x_values[random.randint(0, len(x_values)-1)]) btn_rand_name=tk.Button( window, text='Click', width=15, height=2, command=rand_get_name ) btn_rand_name.pack(pady=30) window.mainloop()

 



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有