颜色改变那段不知道为什么运行时候明明txt文件是空的,但是窗口输入框会有py-等等文字
from tkinter import Label,StringVar,Entry,Button,IntVar,Checkbutton
import tkinter as tk
from selenium import webdriver
import time
import os,shutil
def mkdir(path):
# 引入模块# 去除首位空格
path=path.strip()
# 去除尾部 \ 符号
path=path.rstrip("\\")
os.path.exists(path)
isExists=os.path.exists(path)
# 判断结果
if not isExists:
# 如果不存在则创建目录
# 创建目录操作函数
os.makedirs(path)
shutil.move('msedgedriver.exe','D:\python\shuwei_login')
return True
mkpath = 'D:\python\shuwei_login'
mkdir(mkpath)
root =tk.Tk()
root.title('请输入你的树维账号和密码')
root.geometry("550x120+450+250")
Label(root,text="树维账号").grid(row=0,padx=10, pady=5)
Label(root,text="树维密码").grid(row=1,padx=10, pady=5)
with open(r'D:\python\shuwei_login\zhanghao.txt',encoding = 'utf-8',mode = 'a') as f:
with open(r'D:\python\shuwei_login\mima.txt',encoding = 'utf-8',mode = 'a') as f1:
side = os.path.getsize('D:\python\shuwei_login\zhanghao.txt')
if side != 0:#判断文件是否为空#有内容
v1 = f.readlines()#读取账号
v2 = f1.readlines()#读取密码
else: #TXT文件无内容
v1 = StringVar()
v2 = StringVar()
e1 = Entry(root)
e2 = Entry(root,show="*")
e1.insert(0, v1)#写入账号
e2.insert(0, v2)#写入密码
e1.grid(row=0, column=1, padx=10, pady=5)
e2.grid(row=1, column=1, padx=10, pady=5)
def login_shuwei():#树维登录
zhanghao = e1.get()
mima = e2.get()
def open_web_1():
driver_path = r'D:\python\shuwei_login\msedgedriver.exe'#浏览器路径
driver = webdriver.Edge(executable_path=driver_path)
driver.maximize_window()#最大化网页
driver.get("https://authserver.zjou.edu.cn/cas/login?service=http%3A%2F%2Fnewjwgl.zjou.edu.cn%2Feams%2Flogin.action")#打开指定网页
driver.refresh()#刷新屏幕
def input(zhanghao,mima):
time.sleep(0)
driver.find_element_by_id('username').send_keys(zhanghao)#输入账号
time.sleep(0)
driver.find_element_by_id('password').send_keys(mima)#输入密码
def login():
driver.find_element_by_css_selector('').click()#点击登录
driver.refresh()#刷新屏幕
driver.maximize_window()#最大化网页
time.sleep()
input(zhanghao,mima)#输入账号密码
login()#登录
open_web_1()
def show_password():
if var.get() == 1:
e2.config(show='')
else:
e2.config(show='*')
def remember():#记住账号密码
zhanghao = e1.get()#获取账号输入框内容
mima = e2.get()#获取密码输入框内容
with open('D:\python\shuwei_login\zhanghao.txt','w') as f:#新建文本记录登录密码
f.write(zhanghao)#写入账号
f.close()
with open('D:\python\shuwei_login\mima.txt','w') as f1:
f1.write(mima)#写入密码
var = IntVar()
Button(root,text="登录树维",width=20,command = login_shuwei).grid(row = 2,column = 0, padx = 10, pady = 5)
var = IntVar()
Button(root,text="记住密码",width=20,command = remember).grid(row = 2,column = 2, padx = 10, pady = 5)
var = IntVar()
c = Checkbutton(root,text='显示密码',variable=var,command = show_password).grid(row = 1,column=2, padx=10, pady=5)
def cancel():#切换账号密码
e1.delete(0,'end')
e2.delete(0,'end')
Button (root,text="一键清空",command = cancel,width = 10).grid(row = 0,column = 2,padx = 10,pady = 5)
root.mainloop()
截图看看
我好像发不了截图
页:
[1]