Python图形化界面实现发送新春红包并附带一句新春祝福-----Python

from tkinter import *
import random
root= Tk()
root.title('新年红包来啦!')
root.geometry('960x960')
lb = Label(root,text='同学老师们,新年快乐',\
           bg='#d3fbfb',\
           fg='red',\
           font=('华文新魏',32),\
           width=20,\
           height=2,\
           relief=SUNKEN)
lb.pack()
dic = {}
lis = ['杨坚', '宇文泰', '高欢', '尔朱荣', '拓跋岳', '萧衍', '侯景', '陈庆之', '陈霸先']


def redpacket(cash, person, index):
    if cash > 0 and person != 1:
        n = round(random.uniform(0.01, cash - (0.01 * person)), 2)
        dic[lis[index]] = n
        lbred = Label(root, text=("红包金额"+str(n).ljust(4, "0")), fg="Red", relief=GROOVE)
        lbred.pack(fill=X)
        person -= 1
        cash -= n
        index += 1
        redpacket(cash, person, index)
    else:
        dic[lis[index]] = round(cash, 2)
        lbred = Label(root, text=("红包金额"+str(cash).ljust(4, "0")), fg="Red", relief=GROOVE)
        lbred.pack(fill=X)


redpacket(50, len(lis), 0)
lbblue = Label(root, text=(dic), fg="blue", relief=GROOVE)
lbblue.pack(fill=X)
lbgreen = Label(root, text=("手气最佳:", max(dic.items(), key=lambda x: x[1])), fg="green", relief=GROOVE)
lbgreen.pack(fill=X)
root.mainloop()

from tkinter import *
import random
root= Tk()
root.title('新年红包来啦!')
root.geometry('960x960')
lb = Label(root,text='同学老师们,新年快乐',\
           bg='#d3fbfb',\
           fg='red',\
           font=('华文新魏',32),\
           width=20,\
           height=2,\
           relief=SUNKEN)
lb.pack()
dic = {}
lis = ['杨坚', '宇文泰', '高欢', '尔朱荣', '拓跋岳', '萧衍', '侯景', '陈庆之', '陈霸先']


def redpacket(cash, person, index):
    if cash > 0 and person != 1:
        n = round(random.uniform(0.01, cash - (0.01 * person)), 2)
        dic[lis[index]] = n
        lbred = Label(root, text=("红包金额"+str(n).ljust(4, "0")), fg="Red", relief=GROOVE)
        lbred.pack(fill=X)
        person -= 1
        cash -= n
        index += 1
        redpacket(cash, person, index)
    else:
        dic[lis[index]] = round(cash, 2)
        lbred = Label(root, text=("红包金额"+str(cash).ljust(4, "0")), fg="Red", relief=GROOVE)
        lbred.pack(fill=X)


redpacket(50, len(lis), 0)
lbblue = Label(root, text=(dic), fg="blue", relief=GROOVE)
lbblue.pack(fill=X)
lbgreen = Label(root, text=("手气最佳:", max(dic.items(), key=lambda x: x[1])), fg="green", relief=GROOVE)
lbgreen.pack(fill=X)
root.mainloop()

你可能感兴趣的:(Python,python,数学建模,intellij-idea,数据结构,eclipse)