我写的这个程序出现的bug很奇怪修改了几次还是没有好转。问题出现在登录界面上如果第一次输入错误的密码再次输入正确密码它还提示是错误密码,但如果第一次输入的是正确密码它就正常的进入使用界面了。
```python
#-*- coding:utf-8 -*-
import tkinter as tk
from tkinter import END
import sys
import hashlib
import time
import re
end = 0
password = '3110343740'
class sign:
#创建窗口
def __init__(self,window):
self.init_window = window
#界面布局
def set_the_window(self):
self.init_window.title("登录界面")
self.init_lable = tk.Label(self.init_window,text='请输入密码:;',font=('微软雅体',10),bg='Yellow')
self.init_butter = tk.Button(self.init_window,text='登录',width=20,height=2,font=('微软雅体',12),command=self.abel)
self.clear = tk.Button(self.init_window,text='清除',command=self.clear_text)
self.init_text = tk.Text(show=None,width=25,height=1)
self.state_text = tk.Text(self.init_window)
self.state_tips = tk.Label(self.init_window,text='提示:\n\n请从软件开发者获取密码',font=('宋体',12),fg='Red',width=21,height=3).place(x=20,y=1)
self.clear.place(x=414,y=13)
self.init_text.grid(row=1,column=0)
self.state_text.grid(row=3,column=0)
self.init_butter.grid(row=2,column=0)
self.init_lable.grid(row=0,column=0)
def abel(self):
global password,end
password = password.encode('utf-8')
Myhash = hashlib.md5()
Myhash.update(password)
password = Myhash.hexdigest()
src = self.init_text.get(1.0, END)
a = re.findall('[\u4e00-\u9fa5a-zA-Z0-9]+', src) # 只要字符串中的中文,字母,数字
src = "".join(a)
src = src.encode('utf-8')
myMd5 = hashlib.md5()
myMd5.update(src)
src = myMd5.hexdigest()
if src == password:
self.state_text.insert(END,"密码正确请稍等,正在加载页面......")
end += 1
self.init_window.destroy()
else:
self.state_text.insert(END,"密码输入错误,请重试。\n")
def clear_text(self):
self.state_text.delete(1.0,END)
def strat():
win = tk.Tk()
My = sign(win)
My.set_the_window()
win.mainloop()
strat()
if end == 0:
sys.exit()
else:
pass
class app_formal_window():
def __init__(self,window):
self.init_windows = window
self.init_windows.title('视频爬取')
self.init_windows.geometry('800x857')
#界面布局
def hold(self):
#标签
self.theme = tk.Label(self.init_windows,text='welcome阿白爬虫',font=('微软雅体',20))
self.instructions = tk.Label(self.init_windows,text='使用说明按钮👇',font=('宋体',12),fg='Red')
self.website = tk.Label(self.init_windows,text='请输入要爬取的网站:',font=('等线',15))
#按钮
self.instructions_button = tk.Button(self.init_windows,text='使用说明',bg='lightblue',command=self.instruction_window)
#文本框架
self.website_text = tk.Text(self.init_windows,show=None,height=1,width=60,font=('宋体',15))
#驱动
self.theme.place(x=300,y=0)
self.instructions.place(x=634,y=20)
self.website.place(x=130,y=80)
self.instructions_button.place(x=635,y=48)
self.website_text.place(x=130,y=109)
def instruction_window(self):
with open('使用说明.txt', 'r', encoding='utf-8') as f:
txt = f.read()
use = tk.Tk()
use.title('使用方法')
use.geometry('750x900')
text_write = tk.Text(use,width=750, height=900)
text_write.insert(1.0,txt)
text_write.pack()
use.mainloop()
def strat_main_window():
win = tk.Tk()
My = app_formal_window(win)
My.hold()
win.mainloop()
strat_main_window()
```