赞
踩
在使用text文本的通讯录的基础之上进行了改进
使用GUI图形界面
之前做了一个作业,后面帮别人搞了一个作业,为了跟自己不一样稍微排版了一下之类的
简化了一下代码之类的
上篇的通讯录PythonPython 实例:)手机通讯录(使用text文本记录数据
下面是运行截图:
复制粘贴运行就ok了
贴代码:
-----------------------2021.12.17 简化了一下代码,方便小伙伴截图代码上交word截图---------------------------------
复制直接运行就可以了
-----------------------2022.4.28 评论区大哥提出的bug进行了部分代码进行了一个修改---------------------------------
import tkinter.messagebox import json import os import tkinter root = tkinter.Tk() root.title('通讯录') root.geometry("550x550") file = open("通讯录.txt", mode='a', encoding='utf-8') file.close() def showinfo(): Frame_info = tkinter.Frame(root, height=150, width=180) Frame_info.place(x=40, y=180) name_label = tkinter.Label(Frame_info, text="名字", font=('宋体', 18)) name_label.grid(row=0, column=0) phone_label = tkinter.Label(Frame_info, text="手机号", font=('宋体', 18)) phone_label.grid(row=0, column=1) mail_label = tkinter.Label(Frame_info, text="邮箱", font=('宋体', 18)) mail_label.grid(row=0, column=2) address_label = tkinter.Label(Frame_info, text="地址", font=('宋体', 18)) address_label.grid(row=0, column=3) file = open("通讯录.txt", mode='r', encoding='utf-8') if len(file.read()) != 0: file.seek(0, 0) file_data = file.read() split_info = file_data.split('\n') split_info.remove(split_info[len(split_info) - 1]) name_li = [] # 用于存储联系人姓名的列表 all_info_li = [] # 用于存储所有信息的列表 for i in split_info: dict_info = json.loads(i.replace("\'", '\"')) all_info_li.append(dict_info) row_count = 0 for person_info in all_info_li: row_count += 1 column_count = 0 for title, info_value in person_info.items(): tktest = tkinter.Label(Frame_info, text=info_value, font=('宋体', 15, 'bold')) tktest.grid(row=row_count, column=column_count) column_count += 1 row_count += 1 tktest = tkinter.Label(Frame_info, text=" "*20, font=('宋体', 15, 'bold')) tktest.grid(row=row_count, column=column_count) showinfo() # 添加 def add_def(event):
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。