部分代码
from tkinter import *
from tkinter import ttk
import tkinter.messagebox as messagebox
import random
import time
import pandas as pd
class Root:
# 初始化界面
def __init__(self):
self.i = 0
self.window = Tk() # 创建窗口对象
self.window.title('健康饮食') # 窗口标题
self.window.configure(bg='#FFE4E1') # 窗口底色
self.window.resizable(0, 0) # 限制不能改变窗口大小
self.width = 500
self.heigh = 300
self.screenwidth = self.window.winfo_screenwidth() # 获得当前屏幕的宽宽
self.screenheight = self.window.winfo_screenheight() # 获得当前屏幕的宽高
self.window.geometry('%dx%d+%d+%d' % (self.width, self.heigh, (self.screenwidth- self.width) / 2,
(self.screenheight - self.heigh) / 2))
# 时间显示标签
self.time_label = Label(self.window,bg='#FFE4E1')
self.time_label.place(x=0,y=0)
Label(self.window,text='星期', font=('楷体', 12), width=7,bg='#FFE4E1').place(x=0, y=30)
Label(self.window, text='早餐', font=('楷体', 12),width=7,bg='#FFE4E1').place(x=0, y=90)
Label(self.window, text='午餐', font=('楷体', 12), width=7,bg='#FFE4E1').place(x=0, y=140)
Label(self.window, text='晚餐', font=('楷体', 12), width=7,bg='#FFE4E1').place(x=0, y=190)
# 星期选择
self.var_Level = StringVar()
self.Levels = ['一', '二', '三', '四', '五', '六', '日']
self.week_l = ttk.Combobox(self.window, width=49, heigh=25,textvariable=self.var_Level,
font=('楷体', 12),state='readonly')
self.week_l['values'] = [self.Levels[i] for i in range(len(self.Levels))]
self.week_l.current(0) # 初始为星期一
self.week_l.place(x=61, y=30)
# 菜谱显示文本框
self.outcome1 = Text(self.window, font=('楷体', 12), width=51,bg='#FFE4E1')
self.outcome1.place(x=61, y=80, height=40)
self.outcome2 = Text(self.window,font=('楷体', 12), width=51,bg='#FFE4E1')
self.outcome2.place(x=61, y=130, height=40)
self.outcome3 = Text(self.window, font=('楷体', 12), width=51,bg='#FFE4E1')
self.outcome3.place(x=61, y=180, height=40)
# 抽取按钮
Button(self.window, text='抽取食谱', font=('楷体', 10),width=10, heigh=1,bg='#FFE4E1',relief=GROOVE,activebackground='yellow',
command=self.get_week).place(x=30, y=260)
# 保存按钮
Button(self.window, text='保存', font=('楷体', 10), width=10, heigh=1,bg='#FFE4E1',relief=GROOVE, activebackground='yellow',
command=self.prompt_).place(x=150, y=260)
# 查看历史记录
Button(self.window, text='查看历史记录', font=('楷体', 10), width=12, heigh=1,bg='#FFE4E1', relief=GROOVE,activebackground='yellow',
command=self.view_historical_data).place(x=280, y=260)
# 退出按钮
Button(self.window, text='退出(Q)', font=('楷体', 10),width=10, heigh=1,bg='#FFE4E1', relief=GROOVE,activebackground='yellow',
command=self.quit_).place(x=400, y=260)
self.x = ''
self.display_time()
self.window.mainloop()
# 获得选择的星期几并随机抽取菜单
def get_week(self):
self.outcome1.delete('1.0', 'end')
self.outcome2.delete('1.0', 'end')
self.outcome3.delete('1.0', 'end')
self.p = self.week_l.get()
self.week,self.x2,self.y2,self.z2 = self.get_data(self.p)
self.outcome1.insert('0.1', self.x2)
self.outcome1.insert(INSERT, '\n')
self.outcome2.insert('0.1', self.y2)
self.outcome2.insert(INSERT, '\n')
self.outcome3.insert('0.1', self.z2)
self.outcome3.insert(INSERT, '\n')
首页
保存抽取结果
查看结果
网盘获取完整源码
链接:https://pan.baidu.com/s/17VNZIjPNod5kON9TcFzWiQ?pwd=eu6a
提取码:eu6a
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)