def choose(): window=tk.Tk() window.title("菜单") window.geometry("1000x750") tk.Label(window, text="数据脱敏系统", font=("微软雅黑 -30"),activebackground='pink').place(x=400, y=20) tk.Label(window, text="(请选择)", font=("黑体", 14)).place(x=450, y=60) table_2=tk.Button(window, text="对表格中数据进行脱敏", font=("微软雅黑 -30"),bg='pink',command=table2) table_2.place(x=100, y=330)def table2(): root = tk.Tk()# 这是主窗口,也就是所说的初始界面 window = tk.Toplevel() root.title("欢迎使用本系统") # 窗口名 root.geometry("1000x750") # 窗口大小 # 手机号、身份证号、年龄、出生日期 data = [ {"手机号": "18845298308", "身份证号": "110101199001011234", "年龄": 31, "出生日期": "1990-01-01"}, {"手机号": "13836277378", "身份证号": "110101199002022345", "年龄": 20, "出生日期": "2002-10-25"}]def desensitize_data(): pattern = re.compile(r'1\d{10}|\d{17}[\dXx]') new_data = data.copy() for i in range(len(data)): for key in data[i]: if isinstance(data[i][key], str): new_data[i][key] = re.sub(pattern, replace_sensitive_info, data[i][key]) return new_data def replace_sensitive_info(match): sensitive_info = match.group(0) if re.match(r'^1\d{10}$', sensitive_info): # 匹配手机号 return sensitive_info[0:3] + 'aaaa' + sensitive_info[7:] elif re.match(r'^\d{17}[\dXx]$', sensitive_info): # 匹配身份证号 return sensitive_info[0:8] + 'aaaaaaaa' + sensitive_info[16:] else: return sensitive_info def replace_mask(): global data data = desensitize_data() show_data() def show_original_data(): global data data = [ {"手机号": "18845298308","身份证号": "110101199001011234", "年龄": 31, "出生日期": "1990-01-01"}, {"手机号": "13836277378", "身份证号": "110101199002022345", "年龄": 20, "出生日期": "2002-10-25"}]show_data() replace_mask_btn = Button(root, text="替换脱敏", font=("微软雅黑 -20"),bg='pink',command=replace_mask) replace_mask_btn.place(x=600,y=20) replace_unmask_btn = Button(root, text="还原", font=("微软雅黑 -20"),bg='pink', command=show_original_data) replace_unmask_btn.place(x=180,y=420)点击还原按钮没有反应代码应该怎么改

时间: 2023-07-19 20:55:25 浏览: 34
在show_original_data()函数中,应该在函数内部添加一个展示数据的操作,例如在函数内部添加一个show_data()函数,用于展示数据。修改后的代码如下: ``` def show_original_data(): global data data = [ {"手机号": "18845298308","身份证号": "110101199001011234", "年龄": 31, "出生日期": "1990-01-01"}, {"手机号": "13836277378", "身份证号": "110101199002022345", "年龄": 20, "出生日期": "2002-10-25"} ] show_data() def show_data(): for i in range(len(data)): for key in data[i]: tk.Label(window, text=data[i][key], font=("微软雅黑 -20")).place(x=200+i*200, y=200+40*list(data[i].keys()).index(key)) ``` 同时,在choose()函数中,需要将root改为window,防止两个窗口混淆。修改后的代码如下: ``` def choose(): window=tk.Tk() window.title("菜单") window.geometry("1000x750") tk.Label(window, text="数据脱敏系统", font=("微软雅黑 -30"),activebackground='pink').place(x=400, y=20) tk.Label(window, text="(请选择)", font=("黑体", 14)).place(x=450, y=60) table_2=tk.Button(window, text="对表格中数据进行脱敏", font=("微软雅黑 -30"),bg='pink',command=table2) table_2.place(x=100, y=330) def table2(): window = tk.Toplevel() window.title("欢迎使用本系统") window.geometry("1000x750") # 手机号、身份证号、年龄、出生日期 data = [ {"手机号": "18845298308", "身份证号": "110101199001011234", "年龄": 31, "出生日期": "1990-01-01"}, {"手机号": "13836277378", "身份证号": "110101199002022345", "年龄": 20, "出生日期": "2002-10-25"} ] def desensitize_data(): pattern = re.compile(r'1\d{10}|\d{17}[\dXx]') new_data = data.copy() for i in range(len(data)): for key in data[i]: if isinstance(data[i][key], str): new_data[i][key] = re.sub(pattern, replace_sensitive_info, data[i][key]) return new_data def replace_sensitive_info(match): sensitive_info = match.group(0) if re.match(r'^1\d{10}$', sensitive_info): # 匹配手机号 return sensitive_info[0:3] + 'aaaa' + sensitive_info[7:] elif re.match(r'^\d{17}[\dXx]$', sensitive_info): # 匹配身份证号 return sensitive_info[0:8] + 'aaaaaaaa' + sensitive_info[16:] else: return sensitive_info def replace_mask(): nonlocal data data = desensitize_data() show_data() def show_original_data(): nonlocal data data = [ {"手机号": "18845298308","身份证号": "110101199001011234", "年龄": 31, "出生日期": "1990-01-01"}, {"手机号": "13836277378", "身份证号": "110101199002022345", "年龄": 20, "出生日期": "2002-10-25"} ] show_data() def show_data(): for i in range(len(data)): for key in data[i]: tk.Label(window, text=data[i][key], font=("微软雅黑 -20")).place(x=200+i*200, y=200+40*list(data[i].keys()).index(key)) replace_mask_btn = tk.Button(window, text="替换脱敏", font=("微软雅黑 -20"),bg='pink',command=replace_mask) replace_mask_btn.place(x=600,y=20) replace_unmask_btn = tk.Button(window, text="还原", font=("微软雅黑 -20"),bg='pink', command=show_original_data) replace_unmask_btn.place(x=180,y=420) show_data() ```

相关推荐

import tkinter as tk from tkinter import messagebox, filedialog import pymysql from PIL import Image, ImageTk def clear(): en1.delete(0, 'end') en2.delete(0, 'end') def create_new_window(): new_window = tk.Toplevel(top) new_window.title('登录成功') new_window.geometry('200x150') label = tk.Label(new_window, text='恭喜您,登录成功!') label.pack() # 添加一个标签来显示图片 img_path = filedialog.askopenfilename(title='选择图片', filetypes=(('/3ec76bb35b3b32b2aaf27e8e343c1c88.jpg', '*.jpg'), ('/3ec76bb35b3b32b2aaf27e8e343c1c88.png', '*.png'))) if img_path: img = Image.open(img_path).resize((150, 150)) photo = ImageTk.PhotoImage(img) label_img = tk.Label(new_window, image=photo) label_img.photo = photo label_img.pack() def login(): username = en1.get() password = en2.get() db = pymysql.connect(host='localhost', user='root', passwd='123456', charset='utf8') cursor = db.cursor() cursor.execute("USE dl") sql = "SELECT * FROM users WHERE username='%s'" % username cursor.execute(sql) result = cursor.fetchone() if result is None: messagebox.showerror(title='登录失败', message='用户名错误,登录失败') else: if result[2] != password: messagebox.showerror(title='登录失败', message='密码错误,登录失败') else: create_new_window() db.close() top = tk.Tk() top.title('登录') top.geometry('300x180') # 添加一个菜单栏 menubar = tk.Menu(top) filemenu = tk.Menu(menubar, tearoff=0) filemenu.add_command(label="打开", command=create_new_window) menubar.add_cascade(label="文件", menu=filemenu) top.config(menu=menubar) label1 = tk.Label(top, text='用户名:', width=6) label1.place(x=50, y=30) en1 = tk.Entry(top, width=20) en1.place(x=100, y=30) label2 = tk.Label(top, text='密码:', width=6) label2.place(x=50, y=60) en2 = tk.Entry(top, width=20, show='*') en2.place(x=100, y=60) bt1 = tk.Button(top, width=10, text='登录', command=login) bt1.place(x=50, y=100) bt2 = tk.Button(top, width=10, text='清除', command=clear) bt2.place(x=170, y=100) top.mainloop()当单击“打开”按钮时,在顶层窗口中显示图片“zsy.jpg

import MySQLdb import tkinter as tk import subprocess # 创建主窗口 window = tk.Tk() window.title("连接数据库") # 设计窗口大小 width = 400 height = 280 window.geometry(f"{width}x{height}") # 设置窗口位置,使其居中显示 x = int((window.winfo_screenwidth() - width) / 2) y = int((window.winfo_screenheight() - height) / 2) window.geometry(f"+{x}+{y}") # 创建标签和输入框 host_label = tk.Label(window, text="主机名:") host_label.pack() host_entry = tk.Entry(window) host_entry.pack() username_label = tk.Label(window, text="用户名:") username_label.pack() username_entry = tk.Entry(window) username_entry.pack() password_label = tk.Label(window, text="密码:") password_label.pack() # 创建输入框,并将 show 参数设置为 "*" password_entry = tk.Entry(window, show="*") password_entry.pack() database_label = tk.Label(window, text="数据库:") database_label.pack() database_entry = tk.Entry(window) database_entry.pack() # 创建按钮和回调函数 def connect(): host = host_entry.get() username = username_entry.get() password = password_entry.get() database = database_entry.get() # 尝试连接 try: cnx = MySQLdb.connect(host=host, user=username, password=password, database=database) print("连接成功!") window.destroy() subprocess.run(["python", "ces2.py"]) except MySQLdb.Error as err: print(f"连接失败: {err}") window.destroy() subprocess.run(["python", "mysql_err.py"]) connect_button = tk.Button(window, text="连接", height=3, width=10, command=connect) connect_button.pack() # 运行主循环 window.mainloop() 插入路径为D:\python--\python word\py_mysql\背景图.png的背景图

import tkinter as tk from tkinter import messagebox import pymysql def clear(): en1.delete(0, 'end') en2.delete(0, 'end') def create_new_window(): new_window = tk.Toplevel(top) new_window.title('登录成功') new_window.geometry('200x100') label = tk.Label(new_window, text='恭喜您,登录成功!') label.pack() def login(): username = en1.get() password = en2.get() db = pymysql.connect(host='localhost', user='root', passwd='123456', charset='utf8') cursor = db.cursor() cursor.execute("USE dl") sql = "SELECT * FROM users WHERE username='%s'" % username cursor.execute(sql) result = cursor.fetchone() if result is None: messagebox.showerror(title='登录失败', message='用户名错误,登录失败') else: if result[2] != password: messagebox.showerror(title='登录失败', message='密码错误,登录失败') else: create_new_window() db.close() top = tk.Tk() top.title('登录') top.geometry('300x180') label1 = tk.Label(top, text='用户名:', width=6) label1.place(x=50, y=30) en1 = tk.Entry(top, width=20) en1.place(x=100, y=30) label2 = tk.Label(top, text='密码:', width=6) label2.place(x=50, y=60) en2 = tk.Entry(top, width=20, show='*') en2.place(x=100, y=60) bt1 = tk.Button(top, width=10, text='登录', command=login) bt1.place(x=50, y=100) bt2 = tk.Button(top, width=10, text='清除', command=clear) bt2.place(x=170, y=100) top.mainloop() 添加“打开”菜单按钮的功能,当单击“打开”按钮时,在第5关的顶层窗口中显示图片“zsy.jpg”

优化这段代码import tkinter as tk class TomatoClock: def init(self, work_time=25, rest_time=5, long_rest_time=15): self.work_time = work_time * 60 self.rest_time = rest_time * 60 self.long_rest_time = long_rest_time * 60 self.count = 0 self.is_working = False self.window = tk.Tk() self.window.title("番茄钟") self.window.geometry("300x200") self.window.config(background='white') self.window.option_add("*Font", ("Arial", 20)) self.label = tk.Label(self.window, text="番茄钟", background='white') self.label.pack(pady=10) self.time_label = tk.Label(self.window, text="", background='white') self.time_label.pack(pady=20) self.start_button = tk.Button(self.window, text="开始", command=self.start_timer, background='white') self.start_button.pack(pady=10) def start_timer(self): self.is_working = not self.is_working if self.is_working: self.count += 1 if self.count % 8 == 0: self.count_down(self.long_rest_time) self.label.config(text="休息时间", foreground='white', background='lightblue') elif self.count % 2 == 0: self.count_down(self.rest_time) self.label.config(text="休息时间", foreground='white', background='lightgreen') else: self.count_down(self.work_time) self.label.config(text="工作时间", foreground='white', background='pink') else: self.label.config(text="番茄钟", foreground='black', background='white') def count_down(self, seconds): if seconds == self.work_time: self.window.config(background='pink') else: self.window.config(background='lightgreen' if seconds == self.rest_time else 'lightblue') if seconds == self.long_rest_time: self.count = 0 minute = seconds // 60 second = seconds % 60 self.time_label.config(text="{:02d}:{:02d}".format(minute, second)) if seconds > 0: self.window.after(1000, self.count_down, seconds - 1) else: self.start_timer() def run(self): self.window.mainloop() if name == 'main': clock = TomatoClock() clock.run()

最新推荐

recommend-type

grpcio-1.63.0-cp38-cp38-linux_armv7l.whl

Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。
recommend-type

SQLyog-13.1.3-0.x86Community.exe

SQLyog-13.1.3-0.x86Community
recommend-type

VB自动出题题库系统设计(源代码+系统).rar

计算机专业毕业设计VB精品论文资源
recommend-type

debugpy-1.0.0b2-cp35-cp35m-manylinux1_i686.whl

Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。
recommend-type

实战自学python如何成为大佬(目录):https://blog.csdn.net/weixin-67859959/artic

实战自学python如何成为大佬(目录):https://blog.csdn.net/weixin-67859959/artic
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB柱状图在信号处理中的应用:可视化信号特征和频谱分析

![matlab画柱状图](https://img-blog.csdnimg.cn/3f32348f1c9c4481a6f5931993732f97.png) # 1. MATLAB柱状图概述** MATLAB柱状图是一种图形化工具,用于可视化数据中不同类别或组的分布情况。它通过绘制垂直条形来表示每个类别或组中的数据值。柱状图在信号处理中广泛用于可视化信号特征和进行频谱分析。 柱状图的优点在于其简单易懂,能够直观地展示数据分布。在信号处理中,柱状图可以帮助工程师识别信号中的模式、趋势和异常情况,从而为信号分析和处理提供有价值的见解。 # 2. 柱状图在信号处理中的应用 柱状图在信号处理
recommend-type

用Spring boot和vue写一个登录注册界面

好的,这是一个比较常见的技术问题,我可以为您提供一些参考资料和思路。首先,您可以使用Spring Boot作为后端框架来处理用户认证和注册的逻辑,比如使用Spring Security实现用户登录认证。同时,您还需要设计相应的数据模型和数据库表结构来存储用户信息。在前端方面,您可以使用Vue.js作为框架来构建登录注册页面,使用Axios来发起API请求并和后端进行交互。当然,在实现过程中,还需要考虑一些具体细节,比如数据校验、安全性和用户体验等方面。希望这些信息能够帮助到您。
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。