为了学习python,训练数据处理的能力,突发奇想,自己做一个老黄历进行查询。
仅限于交流学习,不得商用哈,数据是下载别人的,所以友善使用,学到就是赚到啦,创作不易转载请注明链接和出处
黄历数据下载地址:https://download.csdn.net/download/hq606/12314707 (黄历1900-2100黄历all.npy)
本人博客地址 :https://blog.csdn.net/hq606
作者 :hq606
做这个,好处是网上有大量的参考代码,可以参考学东西,主要用到
1.excel表格存为字典(网上有很多代码我就不写了)
2.字典的导入,合并,查询

第一步 .excel表格存为字典(网上有很多代码我就不写了,黄历数据自己随机下载一个,做成字典,就能啦)

第二步 .合并数据,做成字典,保存

有个字典的保存合并的代码挺好用的,直接放出来

import numpy as np
a=np.load('1900-1999黄历去重.npy',allow_pickle=True) #加载字典
b=np.load('2020-2099huangli.npy',allow_pickle=True)#加载字典
c=np.load('黄历2000-2019.npy',allow_pickle=True)#加载字典
print(len(a),len(b),len(c))
all=a.tolist()+c.tolist()+b.tolist()   #转为列表格式
print(len(all))
#print(all)
np.save('1900-2099黄历all.npy', all) #保存字典数据
d=np.load('1900-2099黄历all.npy',allow_pickle=True)
print(d)

第三步 .下来就要用这个"1900-2099黄历all.npy"字典文件,查询实现日历功能。
黄历网上很多,自己做一个字典保存就好了,用numpy 保存和载入
**下面直接上代码,实现功能。**目前比较简单,然后做一个漂亮的可视化界面就更好了。
先看效果吧,字典里面有30多种黄历信息,现在只做了一部分信息出来,其他的相同方法提取字典查询即可

运行默认显示当前日期

然后可以随意查询你想看的日期

加了可视化界面以后

查询窗口


查询结果

代码如下,任意日期查询实现窗口化

import numpy as np
import calendar
import datetime
import time
import tkinter
from tkinter import *    def nowtime():global y,m,dtoday=datetime.date.today()y=today.yearm=today.monthd=today.day# 输入指定年月# 显示日历#print('-----------------------------------------')#print('当前是',str(y),'年',str(m),'月 ',str(d),'日    日历')#print(calendar.month(int(y),int(m)))#print('-----------------------------------------')return calendar.month(int(y),int(m))
#公历 农历  宜0  宜1  忌0  忌1  节日0 节日1 今日八字1   今日八字2   今日八字3   今日八字4   今日五行1   今日五行2   今日五行3   今日五行4   干支  生肖  星座  儒略日 胎神占方    财福喜神    年冲煞 月冲煞 日冲煞 24节气    日出日落时间  彭祖百忌    十二神 黄道
#nowtime()def cx(year2,month,chiceday):d=np.load('1900-2099黄历all.npy',allow_pickle=True)if month<10:day=str(year2)+'0'+str(month)+'月'elif month>=10:day=str(year2)+str(month)+'月'mothday=[]if (month == 1 or month == 3 or month == 5 or month == 7 or month == 8 or month == 10 or month == 12):for i in d:        if day in str(i['公历']):#n+=1mothday.extend([i])#n+=1#print(i)a0='>>>>>>>>>>>>>>>>黄历信息<<<<<<<<<<<<<<<<'a00='-----------------------------------------'        a=mothday[:][chiceday-1]['公历']b=mothday[:][chiceday-1]['农历']c=str('干支>>>>>')+str(mothday[:][chiceday-1]['干支']) d=str(mothday[:][chiceday-1]['宜0'])+'>>>>>'+str(mothday[:][chiceday-1]['宜1'])e=str(mothday[:][chiceday-1]['忌0'])+'>>>>>'+str(mothday[:][chiceday-1]['忌1'])if mothday[:][chiceday-1]['节日']=='':f=str('传统节日')+'>>>>>'+str('无')else:f=str('传统节日')+'>>>>>'+str(mothday[:][chiceday-1]['节日'])g=str('财福喜神>>>>>')+str(mothday[:][chiceday-1]['财福喜神']) h=str('24节气>>>>>')+str(mothday[:][chiceday-1]['24节气'])   i=str('日出日落时间>>>>>')+str(mothday[:][chiceday-1]['日出日落时间']) j=str('彭祖百忌:')+str(mothday[:][chiceday-1]['彭祖百忌'].replace('\n\n',''))k=str('黄道>>>>>')+str(mothday[:][chiceday-1]['黄道'].replace('??',''))        l=(day+'31天')m='-----------------------------------------'  elif (month == 4 or month == 6 or month == 9 or month == 11 ):for i in d:        if day in str(i['公历']):#n+=1mothday.extend([i])#n+=1a0='>>>>>>>>>>>>>>>>黄历信息<<<<<<<<<<<<<<<<'a00='-----------------------------------------'        a=mothday[:-1][chiceday-1]['公历']b=mothday[:-1][chiceday-1]['农历']c=str('干支>>>>>')+str(mothday[:-1][chiceday-1]['干支']) d=str(mothday[:-1][chiceday-1]['宜0'])+'>>>>>'+str(mothday[:-1][chiceday-1]['宜1'])e=str(mothday[:-1][chiceday-1]['忌0'])+'>>>>>'+str(mothday[:-1][chiceday-1]['忌1'])if mothday[:-1][chiceday-1]['节日']=='':f=str('传统节日')+'>>>>>'+str('无')else:f=str('传统节日')+'>>>>>'+str(mothday[:-1][chiceday-1]['节日'])g=str('财福喜神>>>>>')+str(mothday[:-1][chiceday-1]['财福喜神']) h=str('24节气>>>>>')+str(mothday[:-1][chiceday-1]['24节气'])   i=str('日出日落时间>>>>>')+str(mothday[:-1][chiceday-1]['日出日落时间']) j=str('彭祖百忌:')+str(mothday[:-1][chiceday-1]['彭祖百忌'].replace('\n\n',''))k=str('黄道>>>>>')+str(mothday[:-1][chiceday-1]['黄道'].replace('??',''))        l=(day+'30天')m='-----------------------------------------'  elif month == 2 and ((year % 4==0 and year % 100!=0) or (year % 400==0)):for i in d:        if day in str(i['公历']):mothday.extend([i])#n+=1a0='>>>>>>>>>>>>>>>>黄历信息<<<<<<<<<<<<<<<<'a00='-----------------------------------------'        a=mothday[:-2][chiceday-1]['公历']b=mothday[:-2][chiceday-1]['农历']c=str('干支>>>>>')+str(mothday[:-2][chiceday-1]['干支']) d=str(mothday[:-2][chiceday-1]['宜0'])+'>>>>>'+str(mothday[:-2][chiceday-1]['宜1'])e=str(mothday[:-2][chiceday-1]['忌0'])+'>>>>>'+str(mothday[:-2][chiceday-1]['忌1'])if mothday[:-2][chiceday-1]['节日']=='':f=str('传统节日')+'>>>>>'+str('无')else:f=str('传统节日')+'>>>>>'+str(mothday[:-2][chiceday-1]['节日'])g=str('财福喜神>>>>>')+str(mothday[:-2][chiceday-1]['财福喜神']) h=str('24节气>>>>>')+str(mothday[:-2][chiceday-1]['24节气'])   i=str('日出日落时间>>>>>')+str(mothday[:-2][chiceday-1]['日出日落时间']) j=str('彭祖百忌:')+str(mothday[:-2][chiceday-1]['彭祖百忌'].replace('\n\n',''))k=str('黄道>>>>>')+str(mothday[:-2][chiceday-1]['黄道'].replace('??',''))        l=(day+'29天')m='-----------------------------------------'  else:for i in d:        if day in str(i['公历']):#n+=1mothday.extend([i])a0='>>>>>>>>>>>>>>>>黄历信息<<<<<<<<<<<<<<<<'a00='-----------------------------------------'        a=mothday[:-3][chiceday-1]['公历']b=mothday[:-3][chiceday-1]['农历']c=str('干支>>>>>')+str(mothday[:-3][chiceday-1]['干支']) d=str(mothday[:-3][chiceday-1]['宜0'])+'>>>>>'+str(mothday[:-3][chiceday-1]['宜1'])e=str(mothday[:-3][chiceday-1]['忌0'])+'>>>>>'+str(mothday[:-3][chiceday-1]['忌1'])if mothday[:-3][chiceday-1]['节日']=='':f=str('传统节日')+'>>>>>'+str('无')else:f=str('传统节日')+'>>>>>'+str(mothday[:-3][chiceday-1]['节日'])g=str('财福喜神>>>>>')+str(mothday[:-3][chiceday-1]['财福喜神']) h=str('24节气>>>>>')+str(mothday[:-3][chiceday-1]['24节气'])   i=str('日出日落时间>>>>>')+str(mothday[:-3][chiceday-1]['日出日落时间']) j=str('彭祖百忌:')+str(mothday[:-3][chiceday-1]['彭祖百忌'].replace('\n\n',''))k=str('黄道>>>>>')+str(mothday[:-3][chiceday-1]['黄道'].replace('??',''))        l=(day+'28天')m='-----------------------------------------'  #print('\n\n')return a0+'\n'+a00+'\n'+a+'\n'+b+'\n'+ c +'\n'+d+'\n'+e+'\n'+f+ '\n'+g+'\n'+h+'\n'+i+'\n'+j+'\n'+k+'\n'+l+'\n'+m       if __name__ == '__main__':    def newwind():def show():global year, month,chiceday            try:year=int(ent_id1.get())month=int(ent_id2.get())chiceday=int(ent_id3.get())year2=str(year)+'年'print("年:%s" % year)print("月:%s" % month)print("日:%s" % chiceday)print(cx(year2,month,chiceday))frame = tkinter.Toplevel(winNew)frame.title('查询结果')if 1989<year<2100 and 0<chiceday:tkinter.Message(frame, text=cx(year2,month,chiceday), width=500,font=("楷体",15),justify=tkinter.CENTER,fg = "red").grid(row=5, column=2)else:tkinter.Message(frame, text='输入错误重新输入,并补全信息', width=500,font=("楷体",15),justify=tkinter.CENTER,fg = "red").grid(row=5, column=2)passexcept Exception as e:frame = tkinter.Toplevel(winNew)frame.title('查询结果')tkinter.Message(frame, text='输入错误重新输入,并补全信息', width=500,font=("楷体",15),justify=tkinter.CENTER,fg = "red").grid(row=5, column=2)ent_id1.delete(0, "end")ent_id2.delete(0, "end")ent_id3.delete(0, "end")winNew = Toplevel(root)winNew.geometry('320x240')winNew.title('输入年月日查询黄历')lab_id=Label(winNew,text='请输入年(1900-2099):')btn_fd=Button(winNew,text='查询',command=show)ent_id1=Entry(winNew)btn_fd.grid(row = 0,column = 2,sticky = W)lab_id.grid(row = 0,column = 0,sticky = W)ent_id1.grid(row = 0,column = 1,sticky = W)       lab_id=Label(winNew,text='请输入月:')ent_id2=Entry(winNew)lab_id.grid(row = 1,column = 0,sticky = W)ent_id2.grid(row = 1,column = 1,sticky = W)lab_id=Label(winNew,text='请输入日:')ent_id3=Entry(winNew)      lab_id.grid(row = 2,column = 0,sticky = W)ent_id3.grid(row = 2,column = 1,sticky = W)btClose=Button(winNew,text='关闭',command=winNew.destroy)btClose.place(relx=0.7,rely=0.5)def popupmenu(event):mainmenu.post(event.x_root,event.y_root)nowtime()year2=str(y)+'年'month = mchiceday=d    root = Tk()root.geometry('650x600')root.resizable(0,0) root.title('日历') mainmenu = Menu(root)menuFile = Menu(mainmenu,tearoff=0)  # 菜单分组 menuFilemainmenu.add_cascade(label="查询",menu=menuFile)menuFile.add_command(label="点击开始查询",command=newwind)    menuFile.add_command(label="退出",command=root.destroy)#photo =tkinter.PhotoImage("000.png")theLabel = tkinter.Label(root,text='',justify=tkinter.CENTER,compound = tkinter.CENTER,font=("黑体",15),fg = "red",relief=GROOVE)theLabel.pack()       msg1 = Message(root,text=nowtime(),fg='blue',font=("黑体",30),relief=GROOVE)msg1.place(relx=0,y=350,relheight=0.4,width=650)   #lb = tkinter.Label(root,text='',anchor='center',image=photo,compound =tkinter.CENTER,fg='red',font=("黑体",15))#lb.pack()theLabel.configure(text=('当前是'+str(y)+'年'+str(m)+'月 '+str(d)+'日'+'\n'+cx(year2,month,chiceday)))root.config(menu=mainmenu)root.bind('Button-3',popupmenu) # 根窗体绑定鼠标右击响应事件root.mainloop()def testhuangli():   #这个是测试函数  窗口化以后 就不要啦ctrl=1    while ctrl:try:global year, month,chicedaynowtime()            year2=str(y)+'年'#print('当前是',str(y),'年',str(m),'月 ',str(d),'日    日历')                     print('当前是 '+str(y)+'年'+str(m)+'月'+str(d),'日\n',nowtime(),cx(year2,m,d))print('-------------在下面输入具体日期查询黄历---------------')flag=input('是否查询任意日期y or N:  ')if flag=='y':year = int(input('输入Year(1900-2099):  '))month = int(input('输入Month:  '))year2=str(year)+'年'chiceday=int(input('输入day:  '))print('显示查询月份的日历黄历信息','您查询的是',str(year),'年',str(month),'月',  str(chiceday), '日 的日历')#print(nowtime())print(cx(year2,month,chiceday))print('5秒后返回当天日历信息\n\n')time.sleep(5)print('返回当天日历信息')time.sleep(1)else:print('已经退出日历')ctrl=0#findday()except Exception as e:print(e,'查询日期超出正常值,或输入格式非整数数字,请重新输入')

python+tkinter创作老黄历,窗口化显示:择吉,五行,财福喜神相关推荐

  1. python+tkinter使用canvas不显示图片的问题

    python+tkinter中使用canvas 切换不显示图片的问题 一.canvas使用 canvas对象的create_image方法有两个重要的点要注意,一个是格式,第二是要保持持续引用: 1. ...

  2. python tkinter库 密码实时显示_python tkinter库实现气泡屏保和锁屏

    本文实例为大家分享了python tkinter库实现气泡屏保和锁屏的具体代码,供大家参考,具体内容如下 显示效果如下: 代码: import random import tkinter import ...

  3. python tkinter库 密码实时显示_Python3 tkinter基础 Entry show textvariable 密码输入框

    Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda : 4.5.11 typesetting : Markdown ...

  4. Python tkinter之PhotoImage图片显示问题

    作为Python小白的你,有没有遇到过这几个问题? PhotoImage不支持jpg等图片格式: 将PhotoImage放在函数里图片不显示: 循环加入图片只显示一张: 这些难倒了一大批小白,那么接下 ...

  5. python tkinter进度条_在python tkinter中Canvas实现进度条显示的方法

    如下所示: from tkinter import * import time #更新进度条函数 def change_schedule(now_schedule,all_schedule): can ...

  6. python 提示框如何顶层显示_python tkinter之顶层菜单、弹出菜单实例

    我就废话不多说了,直接看代码吧! from tkinter import * def sys_callbak(): pass def fun_callbak(): pass def no_thing( ...

  7. python+tkinter仿制win10标准型计算器(中文版)完美教学

    前言 马上就要实习了,而我却没有拿得出手的项目..哎实力不够啊.还有六个月时间,先从简单开始吧,一步一个脚印,大家一起加油! "设计很难,模仿不易."这是我创作计算器时内心的独白. ...

  8. python tkinter库、添加gui界面_使用Python中tkinter库简单gui界面制作及打包成exe的操作方法(二)...

    使用Python中tkinter库简单gui界面制作及打包成exe的操作方法(二),创建一个,界面,布局,文件,路径 使用Python中tkinter库简单gui界面制作及打包成exe的操作方法(二) ...

  9. python tkinter计算器实例_Python编程使用tkinter模块实现计算器软件完整代码示例

    Python 提供了多个图形开发界面的库.Tkinter就是其中之一. Tkinter 模块(Tk 接口)是 Python 的标准 Tk GUI 工具包的接口 .Tk 和 Tkinter 可以在大多数 ...

最新文章

  1. 单例模式——创建型模式
  2. Myeclipse8.5配置本地tomcat
  3. mysql user 用户名长度_为什么注册的用户账号长度不能超过5个字符
  4. 2017-2018-2 20165211 实验五《网络编程与安全》实验报告
  5. SOAMANAGER配置后无法登录问题
  6. 传腾讯人事大地震 马化腾将重整公司架构
  7. php for嵌套循环_PHP中的for循环怎样嵌套
  8. 查看当前Linux系统的发行版本命令详解
  9. u-boot源码配置原理分析
  10. 利用 sql server agent(sql server代理)实现定时备份
  11. 华为交换机配置时区_把华为交换机设置成时钟源服务器(NTP)
  12. 推送数据分析全新升级,优化方向一目了然
  13. 实对称矩阵的特征值求法_机器学习与线性代数 - 特殊矩阵
  14. BeX5安装遇到问题
  15. 微信java精简版低内存_微信精简版apk下载-微信精简版低内存2016 安卓版_5577安卓网...
  16. pandas 数据透视表
  17. 蓝牙4.0和3.0区别
  18. 哔哩哔哩视频显示在Github的Markdown博客页方法
  19. 单点登录技术:微软Passport单点登录协议和自由联盟规范
  20. android os仿ios,安卓机和iOS系统结合?再也不用去下高仿的iOS主题了

热门文章

  1. Redies未授权访问
  2. Proxy SwitchyOmega安装和使用
  3. 3*3 数字拼图(去除无解的随机组合)
  4. 一个人,向南走了一公里,然后向东走1公里,然后向北走一公里
  5. 【黑帽大牛】浅谈SEO快排系统对网站排名优化真的有帮助吗?【精品】
  6. 来美国一年半了,命里有时终须有,命里无时莫强求(2)
  7. python利用pyinstaller打包文件
  8. Linux端的qbittorrent目录,qBittorrent v4.3.0.10便携增强版-BT/磁力下载软件
  9. 2020年最值得期待的几大BPM厂商一览
  10. DirectDraw关于blt的一些注意事项