# coding=gbkimport tkinter as tk
import tkinter.ttk as ttk
from tkinter import *
from PIL import Image, ImageTk
import tkinter.messagebox
import pickle
from PIL import Image as imim
import pygameroot = Tk()
root.title('赛博功德系统')root_img = ImageTk.PhotoImage(imim.open("bp.png"))
root_img1 = ImageTk.PhotoImage(imim.open('bp1.png'))
root_img2 = ImageTk.PhotoImage(imim.open('QR.png'))canvans_login = Canvas(root, width=900, height=600, highlightthickness=0)  #chick = canvans_login.create_image(0, 0, anchor='nw', image=root_img)
canvans_login.pack()texty = 400
levallist1 = []
count = 0
texty1 = 400
levallist2 = []
count1 = 0pygame.mixer.init()
pygame.mixer.music.load('dabeizhou.mp3')
pygame.mixer.music.set_volume(0.1)
pygame.mixer.music.play()class CreateButton(object):def __init__(self, master=None, canvas=None, x1=None, y1=None, x2=None, y2=None, str1=None, fontsize=30):'''创建按钮:param master: 建立的窗口:param canvas: 画布:param x1: 按钮左上顶点横坐标:param y1: 按钮左上顶点纵坐标:param x2: 按钮右下顶点横坐标:param y2: 按钮右下顶点纵坐标:param str1: 按钮上的文字:param fontsize: 按钮上的字体大小'''self.x1 = x1self.x2 = x2self.y1 = y1self.y2 = y2self.str = str1self.root = masterself.canvas = canvasself.fontsize = fontsizeself.r1 = self.canvas.create_rectangle(self.x1, self.y1, self.x2, self.y2, width=2, outline='white')  # 按钮外框self.r2 = self.canvas.create_rectangle(self.x1 + 3, self.y1 + 3, self.x2 - 3, self.y2 - 3, width=2,outline='white')  # 按钮内框self.t = self.canvas.create_text((self.x1 + self.x2) / 2, (self.y1 + self.y2) / 2, text=self.str,font=('楷体', self.fontsize, 'bold'), fill='white')  # 按钮显示文本self.SetBuuton()def bind_1(self, event=None):  # 点击响应函数passdef bind_2(self, event):  # 鼠标经过响应函数if self.x1 <= event.x <= self.x2 and self.y1 <= event.y <= self.y2:  # 响应的位置self.canvas.itemconfigure(self.r1, outline='gold')  # 重设外框颜色self.canvas.itemconfigure(self.r2, outline='gold')  # 重设内框颜色self.canvas.itemconfigure(self.t, fill='gold')  # 重设显示文本颜色else:self.canvas.itemconfigure(self.r1, outline='white')  # 恢复外框默认颜色self.canvas.itemconfigure(self.r2, outline='white')  # 恢复内框默认颜色self.canvas.itemconfigure(self.t, fill='white')  # 恢复显示文本默认颜色def SetBuuton(self):self.canvas.bind('<Button-1>', lambda event: self.bind_1(event))  # 关联鼠标点击事件self.canvas.bind('<Motion>', lambda event: self.bind_2(event))  # 关联鼠标经过事件flag = 0class LoginPage(object):def __init__(self, master=None):self.flag = 0self.root = master  # 定义内部变量rootself.root.title('登录界面')self.root.geometry('%dx%d' % (300, 200))  # 设置窗口大小self.username = StringVar()self.username.set('e.g.npucs2022666666')self.password = StringVar()def fun(self):  # 执行函数self.createPage()def createPage(self):  # 设置界面函数self.page = Frame(self.root)  # 创建Frameself.page.pack()Label(self.page).grid(row=0, stick=W)Label(self.page, text='账户: ').grid(row=1, stick=W, pady=10)Entry(self.page, textvariable=self.username).grid(row=1, column=1, stick=E)Label(self.page, text='密码: ').grid(row=2, stick=W, pady=10)Entry(self.page, textvariable=self.password, show='*').grid(row=2, column=1, stick=E)Button(self.page, text='登陆', command=self.loginCheck).grid(row=3, stick=W, pady=10)Button(self.page, text='注册', command=self.sign).grid(row=3, column=1, stick=W)Button(self.page, text='退出', command=self.page.quit).grid(row=3, column=1, stick=E)def sign(self):  # 注册函数def sign_up_admin():np = new_psd.get()npf = new_psd_confirm.get()nn = new_name.get()with open('usrs_info.pickle', 'rb') as user_file:exit_user_info = pickle.load(user_file)if np != npf:tk.messagebox.showerror(title="Error", message='两次输入的密码不一致!')elif len(np) == 0:tk.messagebox.showerror(title="Error", message='密码不能为空!')elif nn in exit_user_info:tk.messagebox.showerror(title="Error", message='这个用户名已经被注册了!')else:exit_user_info[nn] = npwith open('usrs_info.pickle', 'wb') as user_file:pickle.dump(exit_user_info, user_file)tk.messagebox.showinfo(title='Welcome', message="注册成功!")root_sign_up.destroy()root_sign_up = tk.Toplevel(self.root)root_sign_up.geometry('350x200')root_sign_up.title('注册界面')new_name = tk.StringVar()new_name.set('e.g.npucs2022666666')tk.Label(root_sign_up, text="用户名:").place(x=10, y=10)entry_new_name = tk.Entry(root_sign_up, textvariable=new_name).place(x=120, y=10)new_psd = tk.StringVar()new_psd.set('')tk.Label(root_sign_up, text="密码:").place(x=10, y=60)entry_new_psd = tk.Entry(root_sign_up, textvariable=new_psd, show='*').place(x=120, y=60)new_psd_confirm = tk.StringVar()new_psd_confirm.set('')tk.Label(root_sign_up, text="请确认密码:").place(x=10, y=110)entry_new_psd_confirm = tk.Entry(root_sign_up, textvariable=new_psd_confirm, show='*').place(x=120, y=110)btn_comfirm_sign_up = tk.Button(root_sign_up, text='注册', command=sign_up_admin)btn_comfirm_sign_up.place(x=170, y=160)def loginCheck(self):  # 登录函数name = self.username.get()secret = self.password.get()try:with open("usrs_info.pickle", 'rb') as user_file:usrs_info = pickle.load(user_file)except FileNotFoundError:with open('usrs_info.pickle', 'wb') as user_file:usrs_info = {'admin': 'admin'}pickle.dump(usrs_info, user_file)if name in usrs_info:if secret == usrs_info[name]:tk.messagebox.showinfo(title="登录成功",message='你好,' + name + '!\n请再次点击进入按钮进入赛博功德系统~')global flagflag = 1self.root.destroy()else:tk.messagebox.showerror(message="密码错误!")else:is_sign_up = tk.messagebox.askyesno(title='Hi', message='你还没有注册,要现在前往注册吗?')if is_sign_up:self.sign()money = 20class MainPage(object):def __init__(self, master=None):self.root = master  # 定义内部变量rootself.root.title('赛博功德系统')self.root.geometry('%dx%d' % (900, 600))  # 设置窗口大小self.money = 0self.volume = 0.5self.count = 0self.funcPage()def funcPage(self):  # 各个功能def Load1():  # 功德-10函数global texty1, count1if texty1 > 340:new2 = self.canvans_main.create_text(380, texty1, anchor='nw', text='功德-10',font=('楷体', 40), fill='black')levallist2.append(new2)self.root.after(5, Load1)if count1 > 0:self.canvans_main.delete(levallist2[count1 - 1])if texty1 == 340:for i in levallist2:self.canvans_main.delete(i)levallist2.clear()texty1 = 400count1 = -1texty1 -= 1count1 += 1def Load():  # 功德+1函数global texty, countif texty > 340:new1 = self.canvans_main.create_text(380, texty, anchor='nw', text='功德+1',font=('楷体', 40), fill='black')levallist1.append(new1)self.root.after(5, Load)if count > 0:self.canvans_main.delete(levallist1[count - 1])if texty == 340:for i in levallist1:self.canvans_main.delete(i)levallist1.clear()texty = 400count = -1texty -= 1count += 1def Laugh(evnet=None):  # 佛祖笑函数'''扣一佛祖陪你笑:return:'''def UpDate():self.canvans_main.update()if self.money < 10:tk.messagebox.showerror(message='功德不足!')else:Load1()mu1 = pygame.mixer.Sound('fozu.mp3')mu1.play()self.canvans_main.update()self.root.update_idletasks()self.root.after(1, UpDate)for i in levallist:self.canvans_main.delete(i)new = self.canvans_main.create_text(10, 10, anchor='nw', text='功德:%d' % (self.money - 10),font=('楷体', 50), fill='white')self.money = self.money - 10levallist.append(new)self.root.update_idletasks()# 扣1佛祖陪你笑self.root.bind('1', Laugh)levallist = []def Knock():  # 敲木鱼self.canvans_main.delete(la3)Load()print('功德+1')self.money = self.money + 1new = self.canvans_main.create_text(10, 10, anchor='nw', text='功德:%d' % (self.money), font=('楷体', 50),fill='white')self.count += 1mu2 = pygame.mixer.Sound('muyu.mp3')mu2.play()for i in levallist:self.canvans_main.delete(i)levallist.append(new)for i in range(self.count - 1):self.canvans_main.delete(levallist[i])self.root.update_idletasks()self.canvans_main = Canvas(self.root, width=900, height=600, highlightthickness=0)  # 主界面的画布self.chick = self.canvans_main.create_image(0, 0, anchor='nw', image=root_img1)self.canvans_main.pack()la3 = self.canvans_main.create_text(10, 10, anchor='nw', text='功德:0', font=('楷体', 50), fill='white')def Helptip():  # 帮助页helptop = tk.Toplevel()helptop.title('帮助')helptop.geometry('400x250')helptext = '帮助\n欢迎进入赛博功德系统\n点击下方按钮敲击木鱼积攒功德\n你可以点击下方按钮消耗功德让佛祖陪你笑\n也可以扣\'1\'快速让佛祖陪你笑\n更多功能正在开发(不会)'tk.Label(helptop, text=helptext, font=('楷体', 15)).pack()b02 = Button(self.root, bg='white', bd=0, font=('楷体', 30), fg='gold', text='帮助', command=Helptip)b02.place(width=120, height=50, x=560, y=10)  # 帮助按钮def Setpage():  # 设置页settop = tk.Toplevel()settop.title('设置')settop.geometry('400x350')abouttext = '   设置'def tip():tk.messagebox.showinfo(message='不会')la01 = tk.Label(settop, text='语言', font=('楷体', 20))la01.place(x=110, y=85)la02 = tk.Label(settop, text='字体', font=('楷体', 20))la02.place(x=110, y=175)la03 = tk.Label(settop, text='音乐', font=('楷体', 20))la03.place(x=110, y=255)b05 = tk.Button(settop, text='简体中文', font=('楷体', 20), command=tip)b05.place(x=210, y=85)b06 = tk.Button(settop, text='楷体', font=('楷体', 20), command=tip)b06.place(x=210, y=165)b07 = tk.Button(settop, text='关闭', font=('楷体', 20), command=tip)b07.place(x=210, y=245)tk.Label(settop, text=abouttext, font=('楷体', 25)).pack()b01 = Button(self.root, bg='white', bd=0, font=('楷体', 30), fg='gold', text='设置', command=Setpage)b01.place(width=120, height=50, x=700, y=10)  # 设置按钮# 关于按钮class About(CreateButton):def __init__(self, master=None, canvas=None, x1=None, y1=None, x2=None, y2=None, str1=None, fontsize=30):'''创建按钮:param master: 建立的窗口:param canvas: 画布:param x1: 按钮左上顶点横坐标:param y1: 按钮左上顶点纵坐标:param x2: 按钮右下顶点横坐标:param y2: 按钮右下顶点纵坐标:param str1: 按钮上的文字:param fontsize: 按钮上的字体大小'''self.x1 = x1self.x2 = x2self.y1 = y1self.y2 = y2self.str = str1self.root = masterself.canvas = canvasself.fontsize = fontsizeself.r1 = self.canvas.create_oval(self.x1, self.y1, self.x2, self.y2, width=2,outline='white')  # 按钮外框self.r2 = self.canvas.create_oval(self.x1 + 3, self.y1 + 3, self.x2 - 3, self.y2 - 3, width=2,outline='white')  # 按钮内框self.t = self.canvas.create_text((self.x1 + self.x2) / 2, (self.y1 + self.y2) / 2, text=self.str,font=('楷体', self.fontsize, 'bold'), fill='white')  # 按钮显示文本self.SetBuuton()def Abouttip(self):abouttop = tk.Toplevel()abouttop.title('关于')abouttop.geometry('330x220')abouttext = '*************************\n\n赛博功德系统V1.0.0\n\n作者:指责型做题乡巴佬\n\n*************************'tk.Label(abouttop, text=abouttext, font=('楷体', 15)).pack()def bind_1(self, event=None):  # 点击响应函数if self.x1 <= event.x <= self.x2 and self.y1 <= event.y <= self.y2:  # 响应的位置self.Abouttip()  # 弹窗About(self.root, self.canvans_main, 830, 10, 880, 60, '?')# 敲木鱼按钮b03 = Button(self.root, text='点击此处敲击木鱼', bd=4, bg='gold', font=('楷体', 30), command=Knock)b03.place(x=50, y=510)# 佛祖笑按钮b04 = Button(self.root, text='扣1佛祖陪你笑', bd=4, bg='gold', font=('楷体', 30), command=Laugh)b04.place(x=500, y=510)def Recharge():  # 充值按钮chargetop = Toplevel(self.root)chargetop.title('功德箱')chargetop.geometry('400x400')tk.Label(chargetop, text='链接安全,请使用微信或浏览器扫一扫', font=('楷体', 15)).pack()tk.Label(chargetop, image=root_img2).pack()b06 = Button(self.root, bg='red', bd=0, font=('楷体', 30), fg='gold', text='功德箱', command=Recharge)b06.place(width=120, height=50, x=780, y=400)  # 设置按钮def enter1(event):event.widget['fg'] = 'yellow';event.widget['bg'] = 'dimgray'def leave1(event):event.widget['fg'] = 'orange';event.widget['bg'] = 'white'def enter2(event):event.widget['fg'] = 'yellow';event.widget['bg'] = 'dimgray'def leave2(event):event.widget['fg'] = 'black';event.widget['bg'] = 'gold'def enter3(event):event.widget['fg'] = 'yellow';event.widget['bg'] = 'dimgray'def leave3(event):event.widget['fg'] = 'black';event.widget['bg'] = 'red'for i in [b01, b02]:i.bind('<Enter>', enter1)i.bind('<Leave>', leave1)  # 按钮关联鼠标进入事件for i in [b03, b04]:i.bind('<Enter>', enter2)i.bind('<Leave>', leave2)b06.bind('<Enter>', enter3)b06.bind('<Leave>', leave3)def login(*args, **kwargs):  # 登录top = Toplevel()LoginPage(top).fun()while flag == 1:top.destroy()canvans_login.destroy()MainPage(root)breakclass LoginButton(CreateButton):  # 登录按钮def bind_1(self, event=None):  # 点击响应函数if self.x1 <= event.x <= self.x2 and self.y1 <= event.y <= self.y2:  # 响应的位置login()##重写父类
LoginButton(root, canvans_login, 380 - 50, 520 - 20, 520 + 50, 570 + 20, '进 入', 60)  # 进入按钮def main():  # 主函数'''主函数:return: 无'''root.mainloop()  # 大型的while循环if __name__ == '__main__':main()

tkinter电子木鱼相关推荐

  1. 最近非常火的电子木鱼流量主小程序源码

    最近非常火的电子木鱼流量主小程序,希望大家也能凑个热度吧. 我看了一下那些人上线的就是手动敲木鱼,然后通过看激励视频自动敲,那么这个源码也是和他们所使用的一样 敲木鱼,功德木鱼通过模拟真实木鱼来精心养 ...

  2. 静心解压,或许你需要一个电子木鱼

    最近被一个客户翻来覆去的需求弄的心烦意乱,血压飙升.于是想起了前段时间特别火的电子木鱼. 打开微信搜索后发现排名前几的木鱼广告满天飞不说,页面还丑的可以. 行叭,谁让咱是程序员呢,咱自己做. 在头秃了 ...

  3. 电子木鱼 微信小程序源码 今天你积功德了吗?

      电子木鱼已经是火了很久的小程序了,今天闲来无事自己搞着玩玩.大家没事可以部署一个放松一下心情.纯属娱乐.大家可以点击看看我部署的项目. 1.首先新建一个微信小程序,这个我就不在演示了. 2.htm ...

  4. 【源码分享】一键打开禅意生活——电子木鱼微信小程序源码分享

    为大家推荐一个在线的AI聊天:魔术AI-8080n点cn界面简洁精美,免费点开即用 在快节奏的现代生活中,我们需要一种方式来减轻压力和焦虑,让我们的身心得到放松和平静.电子木鱼微信小程序是一款专门为人 ...

  5. 电子木鱼网页版(教学+源码带注释)

    近日在网上经常看见电子木鱼的案例,但都是做的小程序,本人就突发奇想,使用css和JavaScript在网页中实现这个功能.于是便有了这个文章.有细致的讲解,也把源码都放在了最后,没有耐心的小伙伴可以直 ...

  6. 微信小程序项目-电子木鱼

    好久之前就看到过电子木鱼这类微信小程序,当时认为这东西热度很快就没了.所以,就没把这项目当作一回事.后来,发现经小红书炒作后,电子木鱼变得越来越红.因此,就有了这个项目. 界面介绍 核心代码 // i ...

  7. Android实现的电子木鱼,功德+1...

    最近被电子木鱼刷屏了,附近的同事也在敲木鱼.... 本想着在百度上搜一个Android代码实现的down下来去装装逼(doge),但是没找到几个合适的.... so!我就自己写个简单的吧! 首先看一下 ...

  8. Compose 动画api之我的电子木鱼青春版

    提示:需要对基本的compose语法有所了解` 文章目录 前言 一.总体规划 二.我的木鱼 1.敲击监听 pointerInput,detectTapGestures 2.木鱼动画 3.木鱼文字 三. ...

  9. Android--简单电子木鱼开发详解

    PS:素材和整个文件我都会放在最后请耐心看完~ 简单看下效果: 页面布局代码: <?xml version="1.0" encoding="utf-8"? ...

最新文章

  1. 程序员最讨厌的9句话,你可有补充?
  2. 如何在多线程中调用winform窗体控件2——实例篇
  3. 下面不属于python第三方库的安装方法的是-关于python中第三方库安装方法和问题解决...
  4. 国内各大音乐平台歌曲分享
  5. IDEA中修改自动生成的Servlet模板,提高编码效率
  6. 小米自然语言处理工程师招聘条件与自己的对应整理
  7. DUBBO与ZOOKEEPER、SPRINGMVC整合和使用
  8. discuz常用变量
  9. Mark—零散知识汇总
  10. eclipse部署Javaweb项目
  11. 小伙用C++搞定远程桌面监控系统,轻松拿下12家offer!
  12. 计算机表格入门2013,Access2013从入门到精通
  13. mysql cmd 关闭防火墙_MySQL WorkBench:Failed to Connect to MySQL at XXX.XXX.XXX with user XXX
  14. 述职答辩提问环节一般可以问些什么_述职提问环节应该提哪些关键问题?
  15. iOS自定义UITableViewRowAction
  16. android sqlite 示例,Android SQLite数据库操作示例
  17. 完整部署uniswap 合约、前端教程(可部署uniswap到bsc、heco)
  18. 书籍推荐《麦肯锡教我的写作武器》
  19. 网站怎么备案?如何快速通过网站备案?网站快速备案攻略请查收!
  20. 【Hack The Box】linux练习-- Tabby

热门文章

  1. oppoK9Pro游戏性能怎么样
  2. 乐优商城之后台管理系统的环境搭建(七)
  3. RPA 百年简史 机器人流程自动化知多少
  4. vue-cli脚手架卡在 ‘98%’ after emitting CopyPlugin 报错,无法运行
  5. 大数据技术原理与应用课后题(林子雨)
  6. 挪威访学2:SOLA UIS 学生宿舍
  7. android 名片识别 简书,nodejs实现名片识别
  8. 使用tesserocr二值化识别知网登录验证码
  9. YoloV3学习笔记(一)—— 打标签
  10. Word 标题样式不统一:有的没有段前,标题前后不一致