基本信息
源码名称:天堂2私服模拟键盘账号自动登陆
源码大小:9.77KB
文件格式:.zip
开发语言:Python
更新时间:2026-03-21
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍
玩天堂2私服有时候需要开多个账号,有丧心病狂之徒甚至开10个左右,这就导致每次登陆账号很痛苦,遂有了此工具。压缩包里是主文件和依赖文件。

#! /usr/bin/env python3
#  -*- coding: utf-8 -*-
#
# GUI module generated by PAGE version 8.1
#  in conjunction with Tcl version 8.6
#    Mar 12, 2026 10:55:43 AM CST  platform: Windows NT

import sys
import tkinter as tk
import tkinter.ttk as ttk
from tkinter.constants import *
import os.path
from tkinter import filedialog
from tkinter import messagebox
import subprocess
import keys
import time

_location = os.path.dirname(__file__)



_bgcolor = 'wheat'
_fgcolor = 'black'
_tabfg1 = 'black' 
_tabfg2 = 'white' 
_bgmode = 'light' 
_tabbg1 = '#d9d9d9' 
_tabbg2 = 'gray40' 

class Toplevel1:
    def __init__(self, top=None):
        self.config_file="id_config.txt"

        top.geometry("410x140 482 153")
        top.minsize(120, 1)
        top.maxsize(1924, 1061)
        top.resizable(0,  0)
        top.title("多账号自动登陆-by mimiwuqi")
        top.configure(background="wheat")
        top.configure(highlightbackground="wheat")
        top.configure(highlightcolor="black")

        try:
            top.iconbitmap("app.ico")
        except Exception as e:
            print(f"加载图标失败{e}")

        self.top = top

        self.Entry_path = tk.Entry(self.top)
        self.Entry_path.place(relx=0.171, rely=0.429, height=20, relwidth=0.659)
        self.Entry_path.configure(background="wheat")
        self.Entry_path.configure(disabledforeground="#b8a786")
        self.Entry_path.configure(exportselection="0")
        self.Entry_path.configure(font="TkFixedFont")
        self.Entry_path.configure(foreground="black")
        self.Entry_path.configure(highlightbackground="wheat")
        self.Entry_path.configure(highlightcolor="black")
        self.Entry_path.configure(insertbackground="black")
        self.Entry_path.configure(selectbackground="#d9d9d9")
        self.Entry_path.configure(selectforeground="black")

        self.Button_open = tk.Button(self.top)
        self.Button_open.place(relx=0.073, rely=0.071, height=25, width=90)
        self.Button_open.configure(activebackground="#d9d9d9")
        self.Button_open.configure(activeforeground="black")
        self.Button_open.configure(background="wheat")
        self.Button_open.configure(compound='left')
        self.Button_open.configure(disabledforeground="#b8a786")
        self.Button_open.configure(foreground="black")
        self.Button_open.configure(highlightbackground="wheat")
        self.Button_open.configure(highlightcolor="black")
        self.Button_open.configure(text='''打开ID文件''')
        self.Button_open.configure(command=self.cmd_open)

        self.Button_save = tk.Button(self.top)
        self.Button_save.place(relx=0.707, rely=0.071, height=25, width=90)
        self.Button_save.configure(activebackground="#d9d9d9")
        self.Button_save.configure(activeforeground="black")
        self.Button_save.configure(background="wheat")
        self.Button_save.configure(compound='left')
        #self.Button_save.configure(cursor="fleur")
        self.Button_save.configure(disabledforeground="#b8a786")
        self.Button_save.configure(foreground="black")
        self.Button_save.configure(highlightbackground="wheat")
        self.Button_save.configure(highlightcolor="black")
        self.Button_save.configure(text='''保存配置''')
        self.Button_save.configure(command=self.cmd_save)

        self.Button_browse = tk.Button(self.top)
        self.Button_browse.place(relx=0.854, rely=0.407, height=26, width=40)
        self.Button_browse.configure(activebackground="#d9d9d9")
        self.Button_browse.configure(activeforeground="black")
        self.Button_browse.configure(background="wheat")
        self.Button_browse.configure(compound='left')
        self.Button_browse.configure(disabledforeground="#b8a786")
        self.Button_browse.configure(foreground="black")
        self.Button_browse.configure(highlightbackground="wheat")
        self.Button_browse.configure(highlightcolor="black")
        self.Button_browse.configure(text='''浏览''')
        self.Button_browse.configure(command=self.button_browse)

        self.Button_start = tk.Button(self.top)
        self.Button_start.place(relx=0.760, rely=0.664, height=30, width=49)
        self.Button_start.configure(activebackground="#d9d9d9")
        self.Button_start.configure(activeforeground="black")
        self.Button_start.configure(background="wheat")
        self.Button_start.configure(compound='left')
        self.Button_start.configure(disabledforeground="#b8a786")
        self.Button_start.configure(foreground="black")
        self.Button_start.configure(highlightbackground="wheat")
        self.Button_start.configure(highlightcolor="black")
        self.Button_start.configure(text='''启动''')
        self.Button_start.configure(command=self.toggle_start_stop)


        self.Entry_time = tk.Entry(self.top)
        self.Entry_time.place(relx=0.341, rely=0.729, height=20, relwidth=0.073)
        self.Entry_time.configure(background="#d9d9d9")
        self.Entry_time.configure(disabledforeground="#b8a786")
        self.Entry_time.configure(exportselection="0")
        self.Entry_time.configure(font="TkFixedFont")
        self.Entry_time.configure(foreground="black")
        self.Entry_time.configure(highlightbackground="wheat")
        self.Entry_time.configure(highlightcolor="black")
        self.Entry_time.configure(insertbackground="black")
        self.Entry_time.configure(selectbackground="#d9d9d9")
        self.Entry_time.configure(selectforeground="black")

        self.Label_path = tk.Label(self.top)
        self.Label_path.place(relx=0.024, rely=0.429, height=17, width=57)
        self.Label_path.configure(activebackground="#d9d9d9")
        self.Label_path.configure(activeforeground="black")
        self.Label_path.configure(anchor='w')
        self.Label_path.configure(background="wheat")
        self.Label_path.configure(compound='left')
        self.Label_path.configure(disabledforeground="#b8a786")
        self.Label_path.configure(foreground="black")
        self.Label_path.configure(highlightbackground="wheat")
        self.Label_path.configure(highlightcolor="black")
        self.Label_path.configure(text='''程序路径''')

        self.Label_time = tk.Label(self.top)
        self.Label_time.place(relx=0.024, rely=0.736, height=15, width=127)
        self.Label_time.configure(activebackground="#d9d9d9")
        self.Label_time.configure(activeforeground="black")
        self.Label_time.configure(anchor='w')
        self.Label_time.configure(background="wheat")
        self.Label_time.configure(compound='left')
        self.Label_time.configure(cursor="fleur")
        self.Label_time.configure(disabledforeground="#b8a786")
        self.Label_time.configure(foreground="black")
        self.Label_time.configure(highlightbackground="wheat")
        self.Label_time.configure(highlightcolor="black")
        self.Label_time.configure(text='''两账号登陆间隔(秒)''')

        self.load_config()
        self.is_running=False
        self.processes=[]

#下面是程序的功能部分
    def button_browse(self):
        filetypes=[
            ("可执行文件","*.exe"),
            ("所有文件","*.*")
        ]
        filename=filedialog.askopenfilename(
                title="选择可执行文件",
                filetypes=filetypes,
                initialdir=os.getcwd()
            )
        if filename:
            self.Entry_path.delete(0,tk.END)
            self.Entry_path.insert(0,filename)

    def cmd_open(self):
        if not os.path.exists(self.config_file):
            with open(self.config_file,'w',encoding='utf-8') as f:
                f.write("user1,password1\n")
                f.write("user2,password2\n")

        os.system(f"notepad {self.config_file}")

    def cmd_save(self):
        path=self.Entry_path.get()
        time=self.Entry_time.get()

        with open("id_config.txt","r",encoding='utf-8') as f:
            lines=f.readlines()

        with open("id_config.txt","w",encoding='utf-8') as f:
            f.write(f"#程序路径: {path}\n")
            f.write(f"#间隔时间: {time}\n")
            f.write("#ID列表:\n")

            for line in lines:
                if not line.startswith("#"):
                    f.write(line)


    def toggle_start_stop(self):
        if not self.is_running:
            self.cmd_start()
            self.Button_start.configure(text="停止")
        else:
            self.cmd_stop()
            self.Button_start.configure(text="启动")

    def cmd_start(self):
        if self.is_running:
            return

        filename=self.Entry_path.get().strip()
        times=self.Entry_time.get().strip()


        if not filename:
            messagebox.showwarning("警告","请先选择程序路径!")
            return

        if not times:
            messagebox.showwarning("警告","请先输入间隔时间!")
            return

        try:
            times=float(times)
        except ValueError:
            messagebox.showerror("错误","间隔时间必须是数字!")
            return
        if not os.path.exists(self.config_file):
            messagebox.showwarning("警告","配置文件不存在!")
            return

        self.ids=[]
        with open(self.config_file,'r',encoding='utf-8') as f:
            for line in f:
                line=line.strip()
                if line and not line.startswith("#"):
                    if "," in line:
                        username,password=line.split(",",1)
                        self.ids.append((username.strip(),password.strip()))
        if not self.ids:
            messagebox.showwarning("警告","配置文件中没有账号")
            return
#以处以下为功能部分,上面是界面部分
        self.is_running=True
        self.current_index=0
        self.Button_start.configure(text="停止")

        self.run_account()

        # for i,(username,password) in enumerate(ids):
        #     try:
        #         subprocess.Popen(filename)
        #         time.sleep(6)
        #         keys.type_text(username)
        #         time.sleep(0.5)
        #         keys.press('tab')
        #         keys.type_text(password)
        #         for j in range(8):
        #             keys.press('enter')
        #             keys.key_up('enter')
        #             time.sleep(0.5)

        #         if i<len(ids)-1:
        #             time.sleep(times)
        #     except Exception as e:
        #         messagebox.showerror("错误",f"启动失败:{str(e)}")
        #         return
        # messagebox.showinfo("Finish",f"已启动{len(ids)}个账号")

    def run_account(self):
        if not self.is_running:
            return

        if self.current_index>=len(self.ids):
            self.finish_all()
            return

        username,password=self.ids[self.current_index]

        try:
            process=subprocess.Popen(self.Entry_path.get().strip())
            self.processes.append(process)

            self.top.after(7000,lambda:self.input_username(username,password))
        except Exception as e:
            messagebox.showerror("错误",f"启动失败:{str(e)}")
            self.cmd_stop()

    def input_username(self,username,password):
        if not self.is_running:
            return

        try:
            keys.type_text(username)
            self.top.after(500,lambda:self.press_tab(password))
        except Exception as e:
            print(f"输入用户名失败:{e}")
            self.cmd_stop()

    def press_tab(self,password):
        if not self.is_running:
            return

        try:
            keys.press('tab')
            self.top.after(500,lambda:self.input_password(password))
        except Exception as e:
            print(f"按tab失败:{e}")
            self.cmd_stop()

    def input_password(self,password):
        if not self.is_running:
            return

        try:
            keys.type_text(password)
            self.press_enter_count=0
            self.press_enter_loop()
        except Exception as e:
            print(f"输入密码失败:{e}")
            self.cmd_stop()

    def press_enter_loop(self):
        if not self.is_running:
            return

        if self.press_enter_count>=8:
            self.current_index =1
            if self.current_index<len(self.ids) and self.is_running:
                interval=float(self.Entry_time.get().strip())*1000
                self.top.after(int(interval),self.run_account)
            else:
                self.finish_all()
            return

        try:
            keys.press('enter')
            keys.key_up('enter')
            self.press_enter_count =1
            self.top.after(500,self.press_enter_loop)
        except Exception as e:
            print(f"按回车失败: {e}")
            self.cmd_stop()

    def finish_all(self):
        self.is_running=False
        self.Button_start.configure(text="启动")
        messagebox.showinfo("完成",f"已启动{len(self.ids)}个账号")

    def cmd_stop(self):
        self.is_running=False

        for process in self.processes:
            try:
                process.terminate()
            except:
                try:
                    process.kill()
                except:
                    pass
        self.processes.clear()
        self.Button_start.configure(text="启动")



    def load_config(self):
        if not os.path.exists(self.config_file):
            return
        try:
            with open(self.config_file,'r',encoding='utf-8') as f:
                for line in f:
                    line=line.strip()
                    if line.startswith("#程序路径:"):
                        path=line.replace("#程序路径:","").strip()
                        self.Entry_path.delete(0,tk.END)
                        self.Entry_path.insert(0,path)
                    elif line.startswith("#间隔时间:"):
                        time=line.replace("#间隔时间:","").strip()
                        self.Entry_time.delete(0,tk.END)
                        self.Entry_time.insert(0,time)
        except Exception as e:
            print(f"加载配置失败:{e}")

if __name__ == '__main__':
    win=tk.Tk()
    app=Toplevel1(win)
    win.mainloop()