在好例子网,分享、交流、成长!
您当前所在位置:首页Python 开发实例Python GUI开发 → 天堂2私服模拟键盘账号自动登陆

天堂2私服模拟键盘账号自动登陆

Python GUI开发

下载此实例
  • 开发语言:Python
  • 实例大小:9.77KB
  • 下载次数:0
  • 浏览次数:0
  • 发布时间:2026-03-21
  • 实例类别:Python GUI开发
  • 发 布 人:秘密武器
  • 文件格式:.zip
  • 所需积分:2
 相关标签: 模拟键盘 自动 登陆 键盘 模拟

实例介绍

【实例简介】玩天堂2私服有时候需要开多个账号,有丧心病狂之徒甚至开10个左右,这就导致每次登陆账号很痛苦,遂有了此工具。压缩包里是主文件和依赖文件。

【实例截图】

from clipboard

【核心代码】#! /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()


实例下载地址

天堂2私服模拟键盘账号自动登陆

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警