关于游戏的录系统的设置能够存档注册还有登录引用,包括分区管理

import sys
import tkinter as tk
from PIL import Image, ImageTk
import os
from datetime import datetime
from guongju.setup import jinchan




# 获取当前时间
current_time = datetime.now()
# 格式化时间
formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
lines = [None] * 3
folder_name = "your_folder_name"
folder_path = os.path.abspath(os.path.join(os.getcwd(), folder_name))  # 如果文件夹不存在,创建它
if not os.path.exists(folder_path):
    os.makedirs(folder_path)
filename = '自动登录保存文件.txt'
path = folder_path  # 你需要指定一个具体的路径
# 设置窗口标题
window = tk.Tk()
window.title("登录界面")
window.overrideredirect(True)  # 隐藏组件栏
img = Image.open('polllll//den//den.png')
photo = ImageTk.PhotoImage(img)  # 创建Label控件并显示图片
label = tk.Label(window, image=photo, highlightbackground="white", highlightthickness=0)
label.image = photo  # 保持对图片的引用
label.place(x=0, y=0, width=580, height=80)  # 放置图片,根据需要修改位置和大小
# 创建账号和密码文本框
account_label = tk.Label(window, text="账号:")
password_label = tk.Label(window, text="密码:")

if os.path.exists(os.path.join(path, filename)):
    with open(os.path.join(path, filename), 'r') as f:
        # 读取所有行并存储到列表中
        lines = [line.strip() for line in f]
def change_button_colors():
    # 将第一个按钮的颜色设置为白色
    buttons[0].config(bg="white")
    # 将其他按钮的颜色重置为蓝色
    for button in buttons[1:]:
        button.config(bg="blue")
def on_button_click(event):
    # 获取当前选中的按钮
    selected_button = event.widget
    # 将所有按钮的颜色重置为蓝色
    for button in buttons:
        button.config(bg="blue")
        # 将选中的按钮的颜色设置为白色
    selected_button.config(bg="white")
def ww(am, x, y, wid, hei):
    img = Image.open('polllll//den//' + am)
    photo = ImageTk.PhotoImage(img)  # 创建Label控件并显示图片
    label = tk.Label(window, image=photo)
    label.image = photo  # 保持对图片的引用
    label.place(x=x, y=y, width=wid, height=hei)  # 放置图片,根据需要修改位置和大小
def den0():
    ww("bai.png", 0, 80, 570, 280)
    label = tk.Label(window, text='———————————^:登录:^———————————')  # 创建 Label 对象并设置文本属性  # 创建 Label 对象
    label.place(x=130, y=100)
    label = tk.Label(window, text=account_label.cget("text"))  # 创建 Label 对象并设置文本属性  # 创建 Label 对象
    label.place(x=200, y=150)
    label = tk.Label(window)  # 创建 Label 对象并设置文本属性  # 创建 Label 对象
    account_entry = tk.Entry(label, width=20)
    account_entry.pack(side=tk.LEFT, padx=0, pady=0)
    label.place(x=250, y=150)
    label = tk.Label(window, text=password_label.cget("text"))  # 创建 Label 对象并设置文本属性  # 创建 Label 对象
    label.place(x=200, y=200)
    label = tk.Label(window)  # 创建 Label 对象并设置文本属性  # 创建 Label 对象
    password_entry = tk.Entry(label, width=20, show="*")
    password_entry.pack(side=tk.LEFT, padx=0, pady=0)
    label.place(x=250, y=200)
    if len(lines) > 2 and lines[2] is not None:
        account_entry.insert('end', lines[0])
        password_entry.insert('end', lines[1])
    def login():
        account = account_entry.get()
        # 去除两边的空格
        account = account.strip()
        # 去除中间的空格
        account = account.replace(" ", "")
        password = password_entry.get()
        # 去除两边的空格
        password = password.strip()
        # 去除中间的空格
        password = password.replace(" ", "")
        folder_path = os.path.abspath(os.path.join(os.getcwd(), folder_name))  # 如果文件夹不存在,创建它
        if os.path.exists(folder_path):
            with open(os.path.join(path, filename), 'w') as file:
                file.write(account+"\n")
                file.write(password+"\n")
                file.write(formatted_time+"\n")
            if not account or not password:
                label = tk.Label(window, text="账号或密码不能为空")
                label.place(x=245, y=300)
                return
            file_name = account + ".txt"  # 要检查的TXT文件名
            full_path = os.path.join(path, account, file_name)
            try:
                with open(full_path, 'r') as file:
                    # 读取所有行并存储到列表中
                    lines = file.readlines()
                    # 处理第一行(如果需要处理其他行,可以在这里添加逻辑)
                    first_line = lines[0].strip().replace(" ", "")

                    if password == first_line:
                        jinchan['b']=account

                        window.destroy()
                    else:
                        label = tk.Label(window, text="账号或密码错误")
                        label.place(x=245, y=300)

            except FileNotFoundError:
                label = tk.Label(window, text="账号不存在,请点击-注册         ")
                label.place(x=245, y=300)
            except Exception as e:
                pass
               # print(f"无法读取文件。错误: {e}")
        else:
                label = tk.Label(window, text="账号不存在,请点击注册         ")
                label.place(x=245, y=300)


    def login2():  # 跟注册相关的代码
        account = account_entry.get()
        # 去除两边的空格
        account = account.strip()
        # 去除中间的空格
        account = account.replace(" ", "")
        password = password_entry.get()
        # 去除两边的空格
        password = password.strip()
        # 去除中间的空格
        password = password.replace(" ", "")


        if not os.path.exists(os.path.join(path, account)):
            os.makedirs(os.path.join(path, account), exist_ok=True)
            folder_path = path +'/'+str(account) # 文件夹路径
            file_name = account  # 要检查的TXT文件名
            file_path = os.path.join(folder_path, file_name + ".txt")
            file_path_2 = os.path.join(folder_path,"该用户关卡进度" + ".txt")

            if os.path.isfile(file_path):
                label = tk.Label(window, text=" 账号已存在                     ")
                label.place(x=245, y=300)
            else:
                try:
                    os.makedirs(folder_path, exist_ok=True)
                    with open(file_path, 'w') as file:
                        file.write(password + "\n")
                    with open(file_path_2, 'w') as file:
                        file.write("玩家游戏名:专注V∽敬业肝的小饭盒" + "\n")
                        file.write("游戏角色:None" + "\n")
                        file.write("当前玩家等级:1"+"\n")
                        file.write("头盔:0"+"\n")
                        file.write("衣服:0"+"\n")
                        file.write("武器:0"+"\n")
                        file.write("鞋子:0"+"\n")
                        file.write("当前坐骑:None"+"\n")
                        file.write("当前法宝:None"+"\n")
                        file.write("当前关卡进度:0" + "\n")
                        file.write("当前所在区域:None" + "\n")
                        file.write("器灵等级:None" + "\n")
                        file.write("跳转地图板块:None" + "\n")
                        file.write("shengmingzhi:1000" + "\n")
                        file.write("fangyuli:200" + "\n")
                        file.write("gongjili:500" + "\n")
                        file.write("baojilv:0.2" + "\n")
                        file.write("baojishanghai:1.5" + "\n")
                except Exception as e:
                    current_time = datetime.now().strftime("%Y年%m月%d日 %H时%M分")
                    # 创建文件内容
                    file_content = f"不知道什么原因导致您无法正常存档,或者存档文件夹已经损坏,请您删除游戏,并且通过重新下载的方式解决!!\n当前时间:{current_time}"
                    # 在桌面创建文件
                    desktop_path = os.path.expanduser("~/Desktop")
                    file_path = os.path.join(desktop_path, "游戏遇到报错问题.txt")
                    with open(file_path, 'w') as file:
                        file.write(file_content)
                    sys.exit(1)
        else:
            if not account or not password:

               label = tk.Label(window, text="不许创建账号或者密码为空")
               label.place(x=245, y=300)
            else:
                label = tk.Label(window, text="账号已经存在了可以登录了")
                label.place(x=245, y=300)
    label = tk.Label(window)
    login_button = tk.Button(label, text="注册", width=10, height=1, command=login2)
    login_button.pack()
    label.place(x=230, y=250)
    label = tk.Label(window)
    login_button2 = tk.Button(label, text="登录", width=10, height=1, command=login)
    login_button2.pack()
    label.place(x=320, y=250)
den0()
def den1():
    img = Image.open('polllll//den//img_1.png')
    photo = ImageTk.PhotoImage(img)  # 创建Label控件并显示图片
    label = tk.Label(window, image=photo)
    label.image = photo  # 保持对图片的引用
    label.place(x=0, y=80, width=570, height=290)  # 放置图片,根据需要修改位置和大小
def den2():
    img = Image.open('polllll//den//img.png')
    photo = ImageTk.PhotoImage(img)  # 创建Label控件并显示图片
    label = tk.Label(window, image=photo)
    label.image = photo  # 保持对图片的引用
    label.place(x=0, y=80, width=570, height=280)  # 放置图片,根据需要修改位置和
def den3():
    ww("bai.png", 0, 80, 570, 280)
    ww("OIP-C.jpg", 0, 146, 240, 260)
    a = "转眼间已经过去两年了"
    b = "语言已经换到了第三种"
    c = "前面几代作下来"
    d = "这应该是第四代游戏了"
    e = "只要梦想还在继续"
    l = "我们在未来就一直可以相约\n            ____天之黎"
    list = [a, b, c, d, e, l]
    y = 190
    label = tk.Label(window,
                     text="本游戏是基于4399旗下的《造梦西游》系列进行改编,属于个人创作的二创类游戏,\n游戏和剧情都基于虚拟搭建,和原著无关。\n并且不会被用于任何商业化,这一款免费玩的二创游戏@",
                     font=("Arial", 10))  # 创建 Label 对象并设置文本属性  # 创建 Label 对象
    label.place(x=60, y=90)
    for i in range(0, len(list)):
        label = tk.Label(window, text=list[i], font=("Arial", 10))  # 创建 Label 对象并设置文本属性  # 创建 Label 对象
        label.place(x=400, y=y)
        y += 20
def center_window(window, width, height):
    # 获取屏幕尺寸
    screen_width = window.winfo_screenwidth()
    screen_height = window.winfo_screenheight()
    # 计算窗口在屏幕上的位置,使其居中
    x = (screen_width / 2) - (width / 2)
    y = (screen_height / 2) - (height / 2)
    # 设置窗口的位置和大小
    window.geometry(f'{width}x{height}+{int(x)}+{int(y)}')
# 定义登录函数

def on_button_click3():
    sys.exit(1)
login_button = tk.Button(window, text="【X】", command=on_button_click3, bg="red", fg="white")
login_button.place(x=530, y=0)
buttons = []
text_r = ["登录与注册", "其他登录", "扫码登录", "关于我们"]
an_r = [den0, den1, den2, den3]
x = 100
for i in range(4):
    button = tk.Button(window, text=text_r[i], width=10, height=1, command=an_r[i])
    if i == 0:  # 第一个按钮的初始颜色为白色
        button.config(bg="white")
    else:  # 其他按钮的初始颜色为蓝色
        button.config(bg="blue")
    button.bind("<Button-1>", on_button_click)  # 使用bind方法来绑定点击事件
    buttons.append(button)
    button.place(x=x, y=50)
    x += 100
# 调用函数,使窗口居中
center_window(window, 570, 350)
window.wm_attributes("-topmost", 1)

window.mainloop()

  • 9
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值