当前位置:   article > 正文

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

python 新年祝福
  1. from tkinter import *
  2. import random
  3. root= Tk()
  4. root.title('新年红包来啦!')
  5. root.geometry('960x960')
  6. lb = Label(root,text='同学老师们,新年快乐',\
  7.            bg='#d3fbfb',\
  8.            fg='red',\
  9.            font=('华文新魏',32),\
  10.            width=20,\
  11.            height=2,\
  12.            relief=SUNKEN)
  13. lb.pack()
  14. dic = {}
  15. lis = ['杨坚', '宇文泰', '高欢', '尔朱荣', '拓跋岳', '萧衍', '侯景', '陈庆之', '陈霸先']
  16. def redpacket(cash, person, index):
  17.     if cash > 0 and person != 1:
  18.         n = round(random.uniform(0.01, cash - (0.01 * person)), 2)
  19.         dic[lis[index]] = n
  20.         lbred = Label(root, text=("红包金额"+str(n).ljust(4, "0")), fg="Red", relief=GROOVE)
  21.         lbred.pack(fill=X)
  22.         person -= 1
  23.         cash -= n
  24.         index += 1
  25.         redpacket(cash, person, index)
  26.     else:
  27.         dic[lis[index]] = round(cash, 2)
  28.         lbred = Label(root, text=("红包金额"+str(cash).ljust(4, "0")), fg="Red", relief=GROOVE)
  29.         lbred.pack(fill=X)
  30. redpacket(50, len(lis), 0)
  31. lbblue = Label(root, text=(dic), fg="blue", relief=GROOVE)
  32. lbblue.pack(fill=X)
  33. lbgreen = Label(root, text=("手气最佳:", max(dic.items(), key=lambda x: x[1])), fg="green", relief=GROOVE)
  34. lbgreen.pack(fill=X)
  35. 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()

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/124226
推荐阅读
相关标签
  

闽ICP备14008679号