实现企业粉丝抽奖

一 代码

def scode9(schoice):
    default_dir = r"lottery.ini"  # 设置默认打开文件为开发路径下的"lottery.ini"
    # 选择包含用户抽奖信息票号的文件,扩展名为“*.ini”
    file_path = tkinter.filedialog.askopenfilename(filetypes=[("Ini file", "*.ini")], title=u"请选择包含抽奖号码的抽奖文件:",
                                                   initialdir=(os.path.expanduser(default_dir)))
    print(os.path.expanduser(default_dir))
    codelist = openfile(file_path)  # 调用 openfile()函数读取刚打开的抽奖文件
    codelist = codelist.split("\n")  # 通过回行转义符把抽奖信息分割成抽奖数列
    incount = inputbox("\033[1;32m     请输入要生成的中奖数量:\33[0m", 1, 0)  # 要求用户输入中(抽)奖数量
    while int(incount) == 0 or len(codelist) < int(incount):  # 如果输入中(抽)奖数量等于0或超过抽奖数组数量,重新输入
        incount = inputbox("\033[1;32m     请输入要生成的抽奖数量:\33[0m", 1, 0)
    strone = random.sample(codelist, int(incount))  # 根据输入的中奖数量进行抽奖

    print("\033[1;35m     抽奖信息名单发布:   \33[0m")
    for i in range(int(incount)):  # 循环将抽奖数列的引号和中括号去掉
        wdata = str(strone[i].replace('[', '')).replace(']', '')  # 将抽奖数列的中括号去掉
        wdata = wdata.replace(''''','').replace(''''', '')  # 将抽奖数列的引号去掉
        print("\033[1;32m         " + wdata + "\33[0m")  # 输出中奖信息

二 运行

猜你喜欢

转载自blog.csdn.net/chengqiuming/article/details/94884574