Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- # import os
- class Person:
- instances = []
- data_from_entries = ''
- search = ''
- def __init__(self, name, subname, sex, age, number, adress):
- self.name = name
- self.subname = subname
- self.sex = sex
- self.age = age
- self.number = number
- self.adress = adress
- self.instances.append(self)
- @staticmethod
- def output():
- # os.system('CLS')
- inp = Person.search
- print(Person.search)
- test = False
- pass_name = set('test set')
- for i in Person.instances:
- if i.subname.strip() == inp.strip():
- test = True
- if not i.name in pass_name:
- print(f'имя: {i.name} \nпол: {i.sex} \nвозраст: {i.age} \nномер: {i.number} \nадрес: {i.adress}')
- pass_name.add(i.name)
- if not test:
- print('Фамилия не найдена')
- print(pass_name)
- @staticmethod
- def append_obj_to_file():
- with open('objects.txt', 'a+', encoding='utf-8') as file:
- data = Person.data_from_entries
- if data.count('не_указано') < 6:
- file.write(data + ' ')
- file.seek(0)
- # s = file.read()
- @staticmethod
- def read_db():
- with open('objects.txt', encoding='utf-8') as file:
- s = file.read().strip().split(' ')
- res = []
- for i in range(0, len(s) - 5, 6):
- res += [s[i: i + 6]]
- return res
- @staticmethod
- def create_objects():
- s = Person.read_db()
- for i in s:
- obj = Person(*i)
- # print('метод create_objects вызван')
- @staticmethod
- def draw_gui():
- root = Tk()
- root.geometry('200x500+200+100')
- def change_spaces(s):
- s = s.replace(' ', '_')
- return s
- def test_button():
- result = [e1.get(), e2.get(), e3.get(), e4.get(), e5.get(), e6.get()]
- result2 = list(map(lambda x: 'не_указано' if x == '' else x, result))
- for i in range(len(result2)):
- result2[i] = change_spaces(result2[i])
- Person.data_from_entries = ' '.join(result2)
- e1.delete(0, END)
- e2.delete(0, END)
- e3.delete(0, END)
- e4.delete(0, END)
- e5.delete(0, END)
- e6.delete(0, END)
- Person.append_obj_to_file()
- Person.create_objects()
- print('имеем двумерный массив данных', Person.read_db(), sep='\n')
- # Person.output()
- def search_name():
- e7.delete(0, END)
- Person.create_objects()
- # print('имеем двумерный массив данных', Person.read_db(), sep='\n')
- Person.search = e7.get()
- Person.output()
- label1 = Label(text='Имя')
- e1 = Entry(width=20)
- label2 = Label(text='Фамилия')
- e2 = Entry(width=20)
- label3 = Label(text='Пол')
- e3 = Entry(width=20)
- label4 = Label(text='Возраст')
- e4 = Entry(width=20)
- label5 = Label(text='Номер')
- e5 = Entry(width=20)
- label6 = Label(text='Адрес')
- e6 = Entry(width=20)
- button = Button(text='Добавить контакт', command=test_button)
- e7 = Entry(width=20)
- button2 = Button(text='Искомая фамилия', command=search_name)
- label7 = Label(text='Результат\n поиска')
- label1.pack()
- e1.pack()
- label2.pack()
- e2.pack()
- label3.pack()
- e3.pack()
- label4.pack()
- e4.pack()
- label5.pack()
- e5.pack()
- label6.pack()
- e6.pack()
- button.pack()
- e7.pack()
- button2.pack()
- label7.pack()
- e1.focus()
- root.mainloop()
- Person.draw_gui()
- # Person.append_obj_to_file()
- # Person.append_obj_to_file()
- # Person.append_obj_to_file()
- # Person.create_objects()
- # Person.output()
- # Person.output()
Advertisement
Add Comment
Please, Sign In to add comment