[Asm] 纯文本查看 复制代码
import random
import tkinter as tk
from tkinter import *#导入模块
from tkinter import messagebox
import datetime
from tkinter.simpledialog import askinteger
import numpy as np
root = tk.Tk()
root.title('决定今天吃的东西')
root.geometry('500x300')
l = tk.Label(root,text='决定今天吃的东西!',bg='red',font=('Arial',12),width=15,height=2)
l.pack()
#root.mainloop()
tan = Button(root)
chuang = Button(root)
tan['text'] = '今天吃什么?'
tan.pack() #设置按钮 并显示文本
def tanchuang(e):
today = datetime.datetime.today()
year, month, day = today.year, today.month, today.day
weekday = datetime.date(year, month, day).strftime("%A")
np.random.seed()
p = np.array([0.35,0.35,0.1,0.1,0.1])
a = np.random.choice(['沙县大酒店','湖南小碗菜','隆江猪脚饭','兰州拉面','江西瓦罐汤'],p=p.ravel())
#messagebox.showinfo('Message', weekday)
#messagebox.showinfo('Message', a)
if weekday == 'Thursday':
print('今天'+weekday+',所以'+'疯狂星期四')
messagebox.showinfo('Message', weekday)
elif a == '沙县大酒店':
b = random.choice(['蒸饺','云吞','鸡腿饭','鸡蛋肉丝炒米粉','养生汤'])
print('今天吃'+a+'的'+b)
messagebox.showinfo('Message', a+'的'+b)
elif a == '湖南小碗菜':
c = random.choice(['娃娃菜','粉丝','腊肠','土豆','排骨'])
print('今天吃'+a+'的'+c)
messagebox.showinfo('Message', a+'的'+c)
elif a == '兰州拉面':
f = random.choice(['红烧牛肉面','香辣牛肉面','番茄鸡蛋面','兰州炒饭','孜然羊肉拌饭'])
print('今天吃' + a + '的'+f)
messagebox.showinfo('Message', a+'的'+f)
elif a == '江西瓦罐汤':
g = random.choice(['土豆回锅肉饭', '葱花煎蛋饭', '榨菜肉丝饭', '四季豆回锅肉饭', '瓦罐汤'])
print('今天吃' + a + '的' + g)
messagebox.showinfo('Message', a+'的'+g)
else:
d = random.choice(['鸭腿饭', '猪脚饭', '猪脚拼烧鸭', '葱油鸡饭', '双拼饭'])
print('今天吃'+a+'的'+d)
messagebox.showinfo('Message', a+'的'+d)
tan.bind('<Button-1>',tanchuang)
root.mainloop() #调用方法 打开弹窗