Home > other >  Python directory
Python directory

Time:11-01

简单点就好

CodePudding user response:

# - * - coding: utf-8 - * -
# author: kaifang 2018/11/21

The from tkinter import *
The from tkinter import the font
The from tkinter import messagebox
The from OS import path
The from OS import remove

"'
Contact management system V1.0
Development of language: Python3
Development tools: pycharm community edition
"'


# to add, edit contact pop-up box class
The class PopupWindow (object) :
# initialized structure and add components to the pop-up box
Def __init__ (self, master, main_window, title, contact=None) :
Self. Main_window=main_window
Top=self. Top=Toplevel (master)
Top. Title (the title)
Top. The resizable (False, False)
W=280
H=320
Top. Geometry (' % dx + + % d % d % d '% (w, h, (ws - w)/2, (hs - h)/2))
Top. Bind (' & lt; Escape> ', lambda event: top. Destroy ())

M_font=the font. The font (size=16)
L=Label (top, text="name:", the font=m_font)
L.p ack (side=TOP, pady=5)
Self. E1=Entry (top)
Self. E1. Pack (side=TOP, padx=16, ipady=3, the fill=X)
Self. E1. Focus ()
If the contact is not None:
Self. E1. Insert (0, contact name)

(top, l2=Label text="telephone number:", the font=m_font)
L2. Pack (side=TOP, pady=5)
Self. E2=Entry (top)
Self. E2. Pack (side=TOP, padx=16, ipady=3, the fill=X)
If the contact is not None:
Self. E2. Insert (0, contact phone_number)

(top, l2=Label text="work units:", the font=m_font)
L2. Pack (side=TOP, pady=5)
Self. E3=Entry (top)
Self. E3. Pack (side=TOP, padx=16, ipady=3, the fill=X)
If the contact is not None:
Self. E3. Insert (0, contact work_place)

(top, l2=Label text="E-mail address:", the font=m_font)
L2. Pack (side=TOP, pady=5)
The self. The e4=Entry (top)
The self. The e4. Pack (side=TOP, padx=16, ipady=3, the fill=X)
If the contact is not None:
The self. The e4. Insert (0, contact e_mail)

If the contact is None:
B2=Button (top, text='add', width=12, the command=lambda: self. Add_click (None))
The self. The e4. Bind (' & lt; Return> ', the self. Add_click)
The else:
B2=Button (top, text='editing', width=12, the command=lambda: self. Edit_click (None))
The self. The e4. Bind (' & lt; Return> ', the self. Edit_click)
B2. Pack (side=LEFT, pady=10, padx=20)
B3=Button (top, text='cancel', width=12, the command=lambda: top. Destroy ())
B3. Pack (side=RIGHT, pady=10, padx=20)

Top. Grab_set ()

# click edit contact button
Def edit_click (self, event) :
E1_name=self. E1. The get ()
If not e1_name:
Messagebox. Showinfo (" wrong ", "name cannot be empty! ')
Return
E2_name=self. E2. The get ()
If not e2_name:
Messagebox. Showinfo (" wrong ", 'phone number can't for empty! ')
Return
E3_name=self. E3. The get ()
E4_name=self. The e4. The get ()
Self. Main_window. Edit_value (e1_name e2_name, e3_name, e4_name)
Self. Top. Destroy ()

# click on the add contact button
Def add_click (self, event) :
E1_name=self. E1. The get ()
If not e1_name:
Messagebox. Showinfo (" wrong ", "name cannot be empty! ')
Return
E2_name=self. E2. The get ()
If not e2_name:
Messagebox. Showinfo (" wrong ", 'phone number can't for empty! ')
Return
E3_name=self. E3. The get ()
E4_name=self. The e4. The get ()
Self. Main_window. Add_value (e1_name e2_name, e3_name, e4_name)
Self. Top. Destroy ()


# main interface class
The class MainWindow (object) :
# the default initialization structure
Def __init__ (self, root) :
The self. The contacts=[]
The self. The root=root
Self. Add_btn_widget ()
Self. Add_search_widget ()
Self. Add_listbox_widget ()
Self. Add_statusbar_widget ()
Self. Read_save_contacts ()
Self. Sel_item=0

# add action button
Def add_btn_widget (self) :
Frame=frame (self. Root)
Frame. Pack (pady=8)
Self. AddBtn=Button (frame, the text='add contact, width=15, the command=lambda: self. The popup (" add contact "))
Self. AddBtn. Pack (padx=5, the fill=X, side=LEFT)
Self. DelAllBtn=Button (frame, the text='delete all contacts, width=15, the command=self. Del_all_contacts)
Self. DelAllBtn. Pack (padx=5, the fill=X, side=LEFT)
Self. SaveAllBtn=Button (frame, the text='keep all contacts, width=15, the command=self. Save_all_contacts)
Self. SaveAllBtn. Pack (padx=5, the fill=X, side=LEFT)

# to add a search box
Def add_search_widget (self) :
Frame=frame (self. Root)
Frame. Pack (pady=8)
Entry1=self. Input_view=Entry (frame, width=34)
Entry1. Insert (0, 'input part name or phone number and press enter query')
Entry1. Bind (" & lt; Button 1 & gt;" , the self. Click_input)
Entry1. Bind (" & lt; FocusOut>" , the self. Focusout_input)
Entry1. Bind (' & lt; Return> ', the self. Search_contact)
Entry1. Bind (' & lt; Escape> ', the self. Cancel_search)
Entry1. Pack (ipady=3, padx=5, side=LEFT)
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related