一、tkinter实现项目小工具
代码语言:javascript
复制# coding=utf-8
"""
@Project :pachong-master
@File :test.py
@Author :gaojs
@Date :2022/8/6 19:54
@Blogs : https://www.gaojs.com.cn
"""
import tkinter
from tkinter import Tk
import tkinter as tk
import sys
import logging
import tkinter.messagebox
import paramiko
from time import sleep
import re
import requests
from faker import Factory
sys.setrecursionlimit(5000)
def create_test_password(sn):
"""
生成test用户密码
"""
url = 'http://10.3.0.50/cgi-bin/passwd_res'
f = Factory.create()
ua = f.user_agent()
headers = {
'User-Agent': ua
}
data = {
'serial': sn
}
rsp = requests.post(url=url, headers=headers, data=data)
passwd = re.findall('password: (.*?)</pre>', rsp.text)[0]
print(passwd)
return passwd
t = tk.Tk()
t.title("test账户密码获取平台")
t.geometry('300x150')
t.resizable(0, 0)
var = tk.StringVar()
# 设置账号
li = tk.Label(t, font='Asia')
li.pack()
tk.Label(text='SN码: ', bg='red').place(x=50, y=30)
uname = tk.Entry(t)
uname.place(x=100, y=30)
# 设置密码
# tk.Label(text='密码: ').place(x=50, y=70)
# pwd = tk.Entry(t)
# pwd.place(x=100, y=70)
def login():
"""
输入sn号,得到test密码
:return:
"""
username = uname.get()
# password = pwd.get()
pwd_result = create_test_password(username)
if username == '':
tk.messagebox.showwarning(title='test账户密码', message='sn码不能为空,请重试!')
else:
tk.messagebox.showinfo(title='test账户密码', message=pwd_result)
print(pwd_result)
tk.Button(text='登录', command=login).place(x=150, y=110)
t.mainloop()
二、效果
1.输入sn码
2.点击登录---->弹出test账户密码
3.sn码为空