当前位置:   article > 正文

Python 实例:手机通讯录(使用GUI图形界面并用text文本记录数据)之二_tkinter简易通信录

tkinter简易通信录

在使用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):
    
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/464778
推荐阅读
相关标签
  

闽ICP备14008679号