Commit e2e7ca63 by BellCodeEditor

auto save

parent 26464189
import tkinter
from tkinter import *
from tkinter import messagebox from tkinter import messagebox
import json import json
class Note(): # 便签、笔记
def __init__(self):
self.root = tkinter.Tk()
self.root.geometry('300x340+1000+200')
self.root.title("我的便签-待办事项")
self.root.resizable(width=False, height=False)
self.bg_img = tkinter.PhotoImage(file="bg.png")
self.box = PhotoImage(file='box.png')
def show(self): # 布置窗口界面
# 画布
self.canvas = tkinter.Canvas(self.root, width=300, height=340)
self.canvas.create_image(0, 0, image=self.bg_img, anchor=NW)
self.canvas.place(x=0, y=0)
# 输入框
self.ent = tkinter.Entry(self.root, show=None,font=('宋体', 13),
bg="snow", width=25)
self.ent.place(x=10, y=310)
# 按钮
self.but = tkinter.Button(self.root,text='添加',font=('宋体', 12),
bg="lightblue", width=5, command=self.get_info)
self.but.place(x=240, y=305)
# 展示所有的文字
self.y = 20
self.val = 0 # 单选框的value参数
self.v = IntVar() # 设置关联变量
for info in alist:
self.canvas.create_text(40, self.y, text=info,
font=("宋体", 11), anchor=W, fill='#FF9900')
# 单选框组件
self.select = tkinter.Radiobutton(self.canvas,image=self.box,
value=self.val,variable=self.v,width=25, height=15,
borderwidth=0,command=self.remove)
self.select.place(x=-20,y=self.y-10)
self.val += 1
self.y += 30
def remove(self): # 清除选中的任务事件
num = self.v.get()
alist.pop(num)
# 更新用户待办事项
content = json.dumps(users)
with open("user.txt", "w", encoding="utf8") as file:
file.write(content)
# 重新渲染便签界面
self.canvas.destroy()
app.show()
def get_info(self): # 获取用户添加的新事件
info = self.ent.get()
self.ent.delete("0", END)
if info != "":
alist.append(info)
# 更新用户待办事项
content = json.dumps(users)
with open("user.txt", "w", encoding="utf8") as file:
file.write(content)
self.canvas.create_text(40,self.y,text=info,font=("宋体",11),
anchor=W, fill='#FF9900')
# 单选框组件
self.select = tkinter.Radiobutton(self.canvas,image=self.box,
value=self.val,variable=self.v,width=25, height=15,
borderwidth=0,command=self.remove)
self.select.place(x=-20,y=self.y-10)
self.val += 1
self.y += 30
# 读取用户信息
with open("user.txt", "r", encoding="utf-8") as f: with open("user.txt", "r", encoding="utf-8") as f:
info = f.read() info = f.read()
users = json.loads(info) users = json.loads(info)
...@@ -26,8 +94,12 @@ def register(): # 注册验证 ...@@ -26,8 +94,12 @@ def register(): # 注册验证
messagebox.showwarning("错误", "用户名已经存在!") messagebox.showwarning("错误", "用户名已经存在!")
elif password1 != password2: elif password1 != password2:
messagebox.showwarning("错误", "两次密码不一致!") messagebox.showwarning("错误", "两次密码不一致!")
else: else: # 通过验证
users[name] = password1 user_info = {}
user_info["password"] = password1
user_info["event"] = ["提示1:可以从输入框添加新任务",
"提示2:点击前面选择框,表示任务完成"]
users[name] = user_info
content = json.dumps(users) content = json.dumps(users)
with open("user.txt", "w", encoding="utf-8") as file: # "w"每次写入都覆盖原来的内容 with open("user.txt", "w", encoding="utf-8") as file: # "w"每次写入都覆盖原来的内容
file.write(content) file.write(content)
...@@ -36,10 +108,16 @@ def register(): # 注册验证 ...@@ -36,10 +108,16 @@ def register(): # 注册验证
reg_to_login() reg_to_login()
def login(): # 登录验证 def login(): # 登录验证
global app,alist
name, password = app_login.get_input() name, password = app_login.get_input()
pwd = users.get(name) # 验证用户名、密码是否正确
if pwd == password: user_name = users.get(name)
messagebox.showinfo("成功", "登录成功") if user_name != None and user_name["password"] == password:
alist = users[name]["event"]
app_login.root.destroy()
app = Note()
app.show()
app.root.mainloop()
else: else:
messagebox.showwarning("错误", "用户名或密码错误!") messagebox.showwarning("错误", "用户名或密码错误!")
......
...@@ -121,4 +121,4 @@ class My_register(): ...@@ -121,4 +121,4 @@ class My_register():
return self.name, self.password1, self.password2 return self.name, self.password1, self.password2
app_login = My_login() app_login = My_login()
app_login.show() app_login.show()
\ No newline at end of file
import tkinter
from tkinter import *
from tkinter import messagebox
import json
class Note(): # 便签、笔记
def __init__(self):
self.root = tkinter.Tk()
self.root.geometry('300x340+1000+200')
self.root.title("待办事项")
self.root.resizable(width=False, height=False)
self.bg_img = tkinter.PhotoImage(file="18.png")
self.box = PhotoImage(file="box.png")
def show(self): # 布置窗口界面
# 画布
self.canvas = tkinter.Canvas(self.root, width=300, height=340)
self.canvas.create_image(0, 0, image=self.bg_img, anchor=NW)
self.canvas.place(x=0, y=0)
# 输入框
self.ent = tkinter.Entry(self.root, show=None,font=("宋体", 13),
bg="pink", width=25)
self.ent.place(x=10, y=310)
# 按钮
self.but = tkinter.Button(self.root,text='添加',font=("宋体", 12),
bg="lightblue", width=5, command=self.get_info)
self.but.place(x=240, y=305)
# 展示所有的文字
self.y = 20
self.val = 0 # 单选框的value参数
self.v = IntVar() # 设置关联变量
for info in alist:
self.canvas.create_text(40, self.y, text=info,
font=("宋体", 13), anchor=W, fill="black")
# 单选框组件
self.select = tkinter.Radiobutton(self.canvas,image=self.box,
value=self.val,variable=self.v,width=25, height=15,
borderwidth=0,command=self.remove)
self.select.place(x=-20,y=self.y-10)
self.val += 1
self.y += 30
def remove(self): # 清除选中的任务事件
num = self.v.get()
alist.pop(num)
# 更新用户待办事项
content = json.dumps(users)
with open("user.txt", "w", encoding="utf8") as file:
file.write(content)
# 重新渲染便签界面
self.canvas.destroy()
app.show()
def get_info(self): # 获取用户添加的新事件
info = self.ent.get()
self.ent.delete("0", END)
if info != "":
alist.append(info)
# 更新用户待办事项
content = json.dumps(users)
with open("user.txt", "w", encoding="utf8") as file:
file.write(content)
self.canvas.create_text(40,self.y,text=info,font=("宋体",11),
anchor=W, fill='#FF9900')
# 单选框组件
self.select = tkinter.Radiobutton(self.canvas,image=self.box,
value=self.val,variable=self.v,width=25, height=15,
borderwidth=0,command=self.remove)
self.select.place(x=-20,y=self.y-10)
self.val += 1
self.y += 30
# 读取用户信息
with open("user.txt", "r", encoding="utf-8") as f:
info = f.read()
users = json.loads(info)
def login_to_reg(): # 登录界面转注册界面
app_login.root.destroy()
global app_reg
app_reg = My_register()
app_reg.show()
def reg_to_login(): # 注册界面转登录界面
app_reg.root.destroy()
global app_login
app_login = My_login()
app_login.show()
def register(): # 注册验证
name,password1,password2 = app_reg.get_input()
if name =="" or password2 == "" or password1=="":
messagebox.showwarning("警告", "请填写完整的注册资料")
elif name in users:
messagebox.showwarning("错误", "用户名已经存在!")
elif password1 != password2:
messagebox.showwarning("错误", "两次密码不一致!")
else: # 通过验证
user_info = {}
user_info["password"] = password1
user_info["event"] = ["可以从输入框添加新任务",
"点击前面选择框,表示任务完成"]
users[name] = user_info
content = json.dumps(users)
with open("user.txt", "w", encoding="utf-8") as file: # "w"每次写入都覆盖原来的内容
file.write(content)
# 注册成功,跳往登陆界面
messagebox.showinfo("成功", "注册成功")
reg_to_login()
def login(): # 登录验证
global app,alist
name, password = app_login.get_input()
# 验证用户名、密码是否正确
user_name = users.get(name)
if user_name != None and user_name["password"] == password:
alist = users[name]["event"]
app_login.root.destroy()
app = Note()
app.show()
app.root.mainloop()
else:
messagebox.showwarning("错误", "用户名或密码错误!")
class My_login(): #登录窗口
def __init__(self):
self.root = tkinter.Tk()#建立窗口对象
self.root.title("登录窗口")#设置窗口标题
self.root.geometry("400x320+500+300")#设置文框大小
self.root.resizable(width=False,height=False)
def show(self):
l = tkinter.Label(self.root,text="登录",font=("宋体",15),
fg="black",width=40,heigh=2,bg="sky blue")
l.place(x=0,y=0)
l= tkinter.Label(self.root,text="账号:",font=("宋体",15),
fg="black",width=5,heigh=2)
l.place(x=85,y=65)
l= tkinter.Label(self.root,text="密码:",font=("宋体",15),
fg="black",width=5,heigh=2)
l.place(x=85,y=125)
self.e1 = tkinter.Entry(self.root,show=None,font=("宋体",14),bg="light grey",width=18)#输入框entry并放置控件,bg支持英文和十六进制;light grey灰色颜色;width文字输入长度
self.e1.place(x=140,y=80)#输入框位置
self.e2 = tkinter.Entry(self.root,show="*",font=("宋体",14),bg="light grey",width=18)
self.e2.place(x=140,y=140)
button1 =tkinter.Button(self.root,text="登录",bg="pink",width=15,
command=login)
button1.place(x=60,y=220)
button2 =tkinter.Button(self.root,text="注册",bg="lightgreen",width=15,
command=login_to_reg)
button2.place(x=230,y=220)
self.root.mainloop()
def get_input(self):
self.name = self.e1.get()
self.password = self.e2.get()
return self.name,self.password
class My_register():
def __init__(self):
self.root = tkinter.Tk()#建立窗口对象
self.root.title("注册窗口")#设置窗口标题
self.root.geometry("400x320+500+300")#设置文框大小
self.root.resizable(width=False,height=False)
def show(self):
self.e1 = tkinter.Entry(self.root,show=None,font=("宋体",14),bg="light grey",width=18)#输入框entry并放置控件,bg支持英文和十六进制;light grey灰色颜色;width文字输入长度
self.e1.place(x=140,y=80)#输入框位置
self.e2 = tkinter.Entry(self.root,show="*",font=("宋体",14),bg="light grey",width=18)
self.e2.place(x=140,y=140)
self.e3 = tkinter.Entry(self.root,show="*",font=("宋体",14),bg="light grey",width=18)
self.e3.place(x=140,y=200)
lad = tkinter.Label(self.root,text="注册",font=("宋体",15),
fg="black",width=40,heigh=2,bg="sky blue")
lad.place(x=0,y=0)
lad1= tkinter.Label(self.root,text="账号:",font=("宋体",12),
fg="black",width=5,heigh=2)
lad1.place(x=90,y=73)
lad2= tkinter.Label(self.root,text="密码:",font=("宋体",12),
fg="black",width=5,heigh=2)
lad2.place(x=90,y=133)
lad3= tkinter.Label(self.root,text="确认密码:",font=("宋体",12),
fg="black",width=9,heigh=2)
lad3.place(x=60,y=193)
button1 =tkinter.Button(self.root,text="注册",bg="lightgreen",width=15,
command=register)
button1.place(x=230,y=250)
button2 =tkinter.Button(self.root,text="取消",bg="red",width=15,
command=reg_to_login)
button2.place(x=60,y=250)
self.root.mainloop()
def get_input(self): # 获取提交的注册信息
self.name = self.e1.get()
self.password1 = self.e2.get()
self.password2 = self.e3.get()
return self.name, self.password1, self.password2
app_login = My_login()
app_login.show()
18.png

331 KB

bg.png

4.47 KB

box.png

636 Bytes

import pygame
from pygame import locals
# 初始化pygame,为使用硬件做准备
pygame.init()
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
# 背景
background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
x, y = 240, 120
position = [(180, 90), (180, 120), (210, 120), (x, y)]
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
x += 30 #
position.append((x, y))
position.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇的头画上去
screen.blit(right, position[-1]) #
# 将贪吃蛇的身体画上去
for i in range(len(position)-1):
screen.blit(body, position[i])
# 将果实画上去
screen.blit(food, (360, 300))
# 刷新画面
pygame.display.update()
FPSCLOCK.tick(3)
\ No newline at end of file
import pygame
from pygame import locals
import random
# 初始化pygame,为使用硬件做准备
pygame.init()
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
# 背景
background = pygame.image.load('bg.png')
right = pygame.image.load('right.png') # 头 朝右
food = pygame.image.load('apple.png') # 食物 苹果
body = pygame.image.load('body.png') # 身体
left = pygame.image.load('left.png') # 头 朝左
up = pygame.image.load('up.png') # 头 朝上
down = pygame.image.load('down.png') # 头 朝下
my_font = pygame.font.Font('neuropol.ttf', 18) # 字体
x, y = 240, 120
position = [(180, 90), (180, 120), (210, 120), (x, y)]
apple_x = 360 # 苹果横坐标
apple_y = 300 # 苹果纵坐标
setheading = "right"
snake_head = right
score = 0
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
if event.type == locals.KEYDOWN:
if event.key == locals.K_RIGHT and setheading != "left":
setheading = 'right'
snake_head = right
if event.key == locals.K_LEFT and setheading != "right":
setheading = 'left'
snake_head = left
if event.key == locals.K_UP and setheading != "down":
setheading = 'up'
snake_head = up
if event.key == locals.K_DOWN and setheading != "up":
setheading = 'down'
snake_head = down
# 设置贪吃蛇的头部坐标
if setheading == "right":
x += 30
elif setheading == "left":
x -= 30
elif setheading == "up":
y -= 30
else:
y += 30
position.append((x, y))
# 贪吃蛇吃到了苹果
if x == apple_x and y == apple_y:
num1= random.randint(1, 22) # 横排第几个格子
num2 = random.randint(1, 16) # 竖排第几个格子
apple_x = 30*num1-30 # 苹果的x坐标
apple_y = 30*num2-30 # 苹果的y坐标
else:
position.pop(0)
# 贪吃蛇撞墙
if x < 0 or x > 630 or y < 0 or y > 450:
exit()
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇的头画上去
screen.blit(snake_head, position[-1])
# 将贪吃蛇的身体画上去
for i in range(len(position)-1):
screen.blit(body, position[i])
# 将果实画上去
screen.blit(food, (apple_x, apple_y))
# 绘制分数
info = "Score:"+ str(score)
text = my_font.render(info, True, (0, 0, 0))
screen.blit(text, (540, 10))
# 刷新画面
pygame.display.update()
FPSCLOCK.tick(3)
\ No newline at end of file
import tkinter
def login_to_reg(): # 登录界面转注册界面
pass
def reg_to_login(): # 注册界面转登录界面
pass
def register(): # 注册验证
pass
def login(): # 登录验证
pass
class My_login(): # 登录窗口
def __init__(self):
self.root = tkinter.Tk()
self.root.title("登录窗口")
self.root.geometry('400x300+500+300')
self.root.resizable(width=False, height=False) # True可以拉伸,False不能拉伸
def show(self): # 登录界面的所有控件
# Label文本标签,界面提示信息
l = tkinter.Label(self.root, text='您好!请登录', bg='green',
font=('宋体', 15), width=40, height=2)
l.place(x=0, y=0)
l = tkinter.Label(self.root, text='用户名:', font=("宋体", 12),
fg="black")
l.place(x=50, y=80)
l = tkinter.Label(self.root, text='密 码:', font=("宋体", 12),
fg="black")
l.place(x=50, y=140)
# Entry单行文本输入框:用户名、密码
self.e1 = tkinter.Entry(self.root, show=None, font=('宋体', 14),
bg="light grey", width=18) # 显示成明文形式
self.e2 = tkinter.Entry(self.root, show='*', font=('宋体', 14),
width=18) # 显示成密文形式
self.e1.place(x=120, y=80)
self.e2.place(x=120, y=140)
# 登录、注册按钮
button1 = tkinter.Button(self.root, text='登录', bg="lightblue",
fg="black", width=15, command=login)
button1.place(x=60, y=220)
button1 = tkinter.Button(self.root, text='注册', bg="lightgreen",
fg="black", width=15, command=login_to_reg)
button1.place(x=230, y=220)
# 进入消息循环,监听事件
self.root.mainloop()
def get_input(self): # 获取输入的用户名、密码
self.name = self.e1.get()
self.password = self.e2.get()
return self.name, self.password
class My_register(): # 注册窗口
def __init__(self):
self.root = tkinter.Tk()
self.root.title("注册窗口")
self.root.geometry('400x320+500+300')
self.root.resizable(width=False, height=False) # True可以拉伸,False不能拉伸
def show(self): # 注册界面的所有控件
# 用户名、密码、确认密码输入框
self.e1 = tkinter.Entry(self.root, show=None, font=('宋体', 14),
bg="light grey", width=18) # 显示成明文形式
self.e1.place(x=140, y=80)
self.e2 = tkinter.Entry(self.root, show='*', font=('宋体', 14),
width=18)
self.e2.place(x=140, y=140)
self.e3 = tkinter.Entry(self.root, show='*', font=('宋体', 14),
width=18)
self.e3.place(x=140, y=200)
# Label文本标签,窗口界面文字:用户名、密码、确认密码
lab = tkinter.Label(self.root, text='您好!请填写注册信息',
font=('宋体', 15),fg="black", width=40, height=2, bg="green")
lab.place(x=0, y=0)
lab1 = tkinter.Label(self.root, text='用户名:', font=("宋体", 12),
fg="black")
lab1.place(x=60, y=80)
lab2 = tkinter.Label(self.root, text='密 码:', font=("宋体", 12),
fg="black")
lab2.place(x=60, y=140)
lab3 = tkinter.Label(self.root, text='确认密码:', font=("宋体", 12),
fg="black")
lab3.place(x=50, y=200)
# 注册界面的提交、取消按钮
button1 = tkinter.Button(self.root, text='提交', bg="lightblue",
width=15,command=register)
button1.place(x=230, y=250)
button1 = tkinter.Button(self.root, text='取消', bg="lightgreen",
width=15, command=reg_to_login)
button1.place(x=80, y=250)
# 进入消息循环
self.root.mainloop()
def get_input(self): # 获取提交的注册信息
self.name = self.e1.get()
self.password1 = self.e2.get()
self.password2 = self.e3.get()
return self.name, self.password1, self.password2
app_login = My_register()
app_login.show()
\ No newline at end of file
{"123": "123", "01": "", "1234": "121245667", "\u5047\u6d88\u606f": "123456"} {"123": "123", "01": "", "1234": "121245667", "\u5047\u6d88\u606f": "123456", "1212": "123456", "\u82cf\u603b": "syf32321", "1933571507": "asdfghjklewq", "121245": "1212"}
\ No newline at end of file \ No newline at end of file
{"123": "123"} {"200": "200", "1212": {"password": "1212", "event": [" ", " ", " ", " ", "\u613f\u6b64\u751f\u76f8\u5b88\u4e4b\u4eba"]}, "123": {"password": "123", "event": ["\u63d0\u793a1\uff1a\u53ef\u4ee5\u4ece\u8f93\u5165\u6846\u6dfb\u52a0\u65b0\u4efb\u52a1", "\u63d0\u793a2\uff1a\u70b9\u51fb\u524d\u9762\u9009\u62e9\u6846\uff0c\u8868\u793a\u4efb\u52a1\u5b8c\u6210"]}, "159": {"password": "1212", "event": []}, "1234": {"password": "123", "event": ["\u53ef\u4ee5\u4ece\u8f93\u5165\u6846\u6dfb\u52a0\u65b0\u4efb\u52a1", "\u70b9\u51fb\u524d\u9762\u9009\u62e9\u6846\uff0c\u8868\u793a\u4efb\u52a1\u5b8c\u6210"]}}
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment