3_significant software.zip
立即下载
资源介绍:
3_significant software.zip
import pygame
import sys
from pygame.locals import *
import tkinter as tk
import json
from tkinter import ttk
a=0
a1=""
a2=""
b1=""
def main():
root = tk.Tk()
root.title("Tkinter 表格示例")
with open("test.json", "r",encoding="utf-8") as f:
list1 = json.load(f)
length=len(list1)
# 创建Treeview控件
tree = ttk.Treeview(root, columns=("ID", "Name", "Age"), show="headings")
tree.heading("ID", text="ID")
tree.heading("Name", text="VALUE")
tree.heading("Age", text="KEY")
# 插入数据
for i in range(1,length+1):
a1=list1[i-1]
keys=a1.keys()
values=a1.values()
keys=str(keys)
keys=keys[11:-2]
values=str(values)
values=values[13:-2]
tree.insert("", "end", values=(i,keys,values))
tree.pack(expand=True, fill="both")
root.mainloop()
def tkin1():
def close():
root.destroy()
def confirm():
global a1, b1
a1 = entry_1.get()
b1 = entry_2.get()
print(a1)
print(b1)
close()
root = tk.Tk()
root.title("输入框")
root.geometry("600x400+530+80")
label_1 = tk.Label(root, text='KEY:', font=('Arial', 12))
label_2 = tk.Label(root, text='VALUE:', font=('Arial', 12))
label_1.place(x=50, y=100)
label_2.place(x=50, y=155)
entry_1 = tk.Entry(root)
entry_1.place(x=250, y=100, width=100)
entry_2 = tk.Entry(root)
entry_2.place(x=250, y=155, width=100)
button1 = tk.Button(root, text='确认', width=20, command=confirm) # 修正了宽度和command
button1.place(x=320, y=340, height=30) # 移除了不必要的width参数
button2 = tk.Button(root, text='取消', width=20, command=close) # 修正了width和command
button2.place(x=420, y=340, height=30) # 调整了位置以避免重叠
root.mainloop()
def tkin2():
def close():
root.destroy()
def confirm():
global a2
a2 = entry_1.get()
print(a2)
close()
root = tk.Tk()
root.title("输入框")
root.geometry("600x400+530+80")
label_1 = tk.Label(root, text='KEY:', font=('Arial', 12))
label_1.place(x=50, y=100)
entry_1 = tk.Entry(root)
entry_1.place(x=250, y=100, width=100)
button1 = tk.Button(root, text='确认', width=20, command=confirm) # 修正了宽度和command
button1.place(x=320, y=340, height=30) # 移除了不必要的width参数
button2 = tk.Button(root, text='取消', width=20, command=close) # 修正了width和command
button2.place(x=420, y=340, height=30) # 调整了位置以避免重叠
root.mainloop()
class Button:
def __init__(self, x, y, width, height, text, color_inactive=(100, 100, 100), color_active=(50, 150, 50)):
self.rect = pygame.Rect(x, y, width, height)
self.color_inactive = color_inactive
self.color_active = color_active
self.color = self.color_inactive
self.text = text
self.font = pygame.font.Font('MiSans-Heavy.ttf', 36) # 使用默认字体,大小36
self.text_image = self.font.render(self.text, True, (255, 255, 255)) # 白色文本
self.text_rect = self.text_image.get_rect(center=self.rect.center) # 文本居中
def is_clicked(self, event):
# 检查鼠标点击是否在按钮上
if event.type == MOUSEBUTTONDOWN:
if self.rect.collidepoint(event.pos):
self.color = self.color_active # 改变按钮颜色以表示它被点击
return True
elif event.type == MOUSEBUTTONUP:
self.color = self.color_inactive # 鼠标释放时恢复按钮颜色
return False
def draw(self, surface):
# 绘制按钮和文本
pygame.draw.rect(surface, self.color, self.rect)
surface.blit(self.text_image, self.text_rect)
text1="不存在"
pygame.init()
screen = pygame.display.set_mode((1280, 720))
background = pygame.image.load("0.jpg")
button1 = Button(100, 100, 200, 50, "创建")
button2 = Button(100, 200, 200, 50, "删除")
button3 = Button(100, 300, 200, 50, "查询")
button4 = Button(100, 400, 200, 50, "退出")
button5 = Button(400, 400, 200, 50, "表格")
running=0
screen.blit(background,(0,0))
while True:
while running==0:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = 1
elif button1.is_clicked(event) :
a=1
elif button2.is_clicked(event) :
a=2
elif button3.is_clicked(event) :
a=3
elif button4.is_clicked(event) :
a=0
elif button5.is_clicked(event) :
a=7
screen.blit(background,(0,0))
button4.draw(screen)
button5.draw(screen)
if a==0:
button1.draw(screen)
button2.draw(screen)
button3.draw(screen)
elif a==1:
tkin1()
try:
with open("test.json", "r",encoding="utf-8") as f:
list1 = json.load(f)
except FileNotFoundError:
list1 = []
found = False
for item in list1:
if a1 in item:
print(f"VALUE是{item[a1]}")
found = True
break
if not found:
dictionary1 = {a1: b1}
list1.append(dictionary1)
print(f"已添加 {dictionary1} 到列表中")
# 将更新后的列表写回JSON文件
with open("test.json", "w", encoding='utf-8') as a:
json.dump(list1, a, ensure_ascii=False, indent=4) # 使用indent使JSON文件更易读
print("程序已退出。")
a=0
elif a==2:
with open("test.json", "w") as a:
json.dump([],a,ensure_ascii=False)
text1="数据已被全部删除"
elif a==3:
tkin2()
try:
with open("test.json", "r",encoding="utf-8") as f:
data = json.load(f)
# 检查data是否是列表
if isinstance(data, list):
found = False
for item in data:
if isinstance(item, dict) and a2 in item:
print(f"VALUE是{item[a2]}")
text1=item[a2]
a=4
found = True
if not found:
print("该KEY在JSON文件中的任何字典中都不存在")
a=5
else:
# 假设data是一个字典
if a2 in data:
print(f"VALUE是{data[key1]}")
else:
print("该KEY在JSON文件中不存在")
a=5
except json.JSONDecodeError:
print("无法解析JSON文件,请检查文件内容")
except Exception as e:
print(f"发生了一个错误:{e}")
elif a==4:
text=str(text1)
font = pygame.font.Font('MiSans-Heavy.ttf', 53)
text_surface = font.render(text, True, (255, 255, 255))
text_rect = text_surface.get_rect(center=(640, 120))
screen.blit(text_surface, text_rect)
elif a==5:
font = pygame.font.Font('MiSans-Heavy.ttf', 53)
text_surface1 = font.render(text1, True, (255, 255, 255))
text_rect1 = text_surface1.get_rect(center=(640, 120))
screen.blit(text_surface1, text_