鱼C论坛

 找回密码
 立即注册
查看: 2234|回复: 0

[萌新报道] 很简单的电话簿

[复制链接]
发表于 2020-7-18 22:23:18 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. import easygui as gui
  2. import pickle
  3. import os

  4. def chart():
  5.     choice = ["1.添加联系人","2.删除联系人","3.查找联系人","4.打印所有","5.退出程序"]
  6.     reply = gui.choicebox("欢迎使用本程序,请选择您所需要的功能:",choices=choice)
  7.     return reply


  8. def add_contacts():
  9.     fields=['姓名:','联系方式:']
  10.     values=gui.multenterbox(msg="1.添加联系人",fields=fields)
  11.     name = values[0]
  12.     numbers = values[1]

  13.     a[name] = numbers

  14. def del_contacts():
  15.     fields=['姓名:']
  16.     values=gui.multenterbox(msg="2.删除联系人",fields=fields)
  17.     name = values[0]

  18.     a.pop(name)   

  19. def find_contacts():
  20.     name = gui.enterbox(msg="请输入待查找的联系人姓名:")
  21.     x = a.get(name)
  22.     if (x):
  23.         gui.msgbox(msg='姓名:     %s \n联系方式:%s'%(name,x),title='联系人详细信息')
  24.     else:
  25.         gui.msgbox(msg='您所查找的联系人不存在')

  26. def save():
  27.     f = open("a.pkl",'wb')
  28.     pickle.dump(a,f)
  29.     f.close()

  30. def read():
  31.     f = open("a.pkl",'rb')
  32.     a = pickle.load(f)
  33.     f.close()
  34.     return a

  35. def print_all():
  36.     choice = []
  37.     for eachkey in a.keys():
  38.         choice.append(eachkey)
  39.     name = gui.choicebox(msg='所有联系人:',choices=choice)
  40.     x = a.get(name)
  41.     if (x):
  42.         gui.msgbox(msg='姓名:     %s \n联系方式:%s'%(name,x),title='联系人详细信息')
  43.     else:
  44.         gui.msgbox(msg='您所查找的联系人不存在')


  45. while (1):
  46.     all_files = os.listdir(os.curdir)
  47.     if ("a.pkl" in all_files):
  48.         a = read()
  49.     else:
  50.         a = {}

  51.     reply = chart()

  52.     if (reply == '1.添加联系人'):
  53.         add_contacts()
  54.         save()
  55.         a = read()
  56.         print_all()

  57.     elif (reply == '2.删除联系人'):
  58.         del_contacts()
  59.         save()
  60.         a = read()
  61.         print_all()

  62.     elif (reply == '3.查找联系人'):
  63.         find_contacts()

  64.     elif (reply == '4.打印所有'):
  65.         print_all()
  66.     elif (reply == '5.退出程序'):
  67.         save()
  68.         break
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-29 04:54

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表