Я работаю над созданием программного обеспечения, в котором я не хочу приостанавливать / останавливать поток в течение некоторого времени или для какого-либо события. Вот некоторый необходимый код, чтобы лучше вас понять
self.staff_list_thread = Thread(target = self.get_staff_list, kwargs = {"master": self.frame_staff_list}, daemon = True)
self.staff_list_thread.start()
def get_staff_list(self, master, *args, **kwargs):
def add_staff_button_callback():
self.get_add_staff(self.frame_staff_add)
def detail_edit_staff_button_callback(email):
if email is not None:
self.get_detail_edit_staff(self.frame_staff_detail, email)
row = 1
self.staff_introduction = get_a_label(master, text="This is staff area", row=0, column=0, padx=(10, 10), pady=(10, 10))
self.staff_introduction.config(style="Title.TLabel")
self.add_staff_button = get_a_button(master, text="Add New Staff", row=0, column=1, padx=(10, 10), pady=(10, 10), ipadx=7, ipady=4)
self.add_staff_button.config(command=add_staff_button_callback)
staffs = self.get_staff_queryset()
if staffs is not None:
for staff in staffs:
self.staff_data_button = get_a_button(master, text='{} as {}'.format(staff[1], staff[5]), row=row, column=0, padx=(0, 0), pady=(5, 5), ipadx=10, ipady=10, relief=FLAT, use_ttk=False)
self.staff_data_button.config(command = lambda email=staff[2]: detail_edit_staff_button_callback(email))
row = row + 1
В концефункция Я не хочу заканчивать паузу потока, и когда добавляется новый персонал, я не хочу пересчитывать или сбрасывать список с текущими данными, поэтому мне нужно снова запустить поток Вот кнопка вызова func
def get_add_staff(self, master, *args, **kwargs):
self.add_staff_current = True
if self.have_one_detail:
# self.destroy_child(self.frame_staff_detail)
self.have_one_detail = False
self.frame_staff_detail.destroy()
self.frame_staff_detail = get_a_frame(self.staff_add_update_panedwindow, column=1, sticky="wn")
FullName, Email, Phone, Joining, Designation, Active = self.get_staff_variable()
def cancel_new_staff_button_callback():
# self.destroy_child(master)
self.frame_staff_detail.destroy()
self.frame_staff_detail = get_a_frame(self.staff_add_update_panedwindow, column=1, sticky="wn")
self.add_staff_current = False
def staff_button_callback():
data = {
'full_name': FullName.get(),
'email': Email.get(),
'phone': float(Phone.get()),
'joining': Joining.get(),
'designation': Designation.get(),
'responsibility': self.add_staff_responsibility_data.get(1.0, 'end'),
'about': self.add_staff_about_data.get(1.0, 'end'),
'active': Active.get()
}
execute = self.execute_staff_data(data=data)
if execute is True:
# self.staff_list_thread.start()
cancel_new_staff_button_callback()
self.get_staff_labels(master)
self.add_staff_fullname_data = get_a_entry(master, textvariable=FullName, width=36, row=1, column=1)
self.add_staff_email_data = get_a_entry(master, textvariable=Email, row=2, width=36, column=1)
self.add_staff_phone_data = get_a_entry(master, textvariable=Phone, row=3, column=1)
self.add_staff_joining_data = get_a_entry(master, textvariable=Joining, row=4, column=1)
self.add_staff_designation_data = get_a_entry(master, textvariable=Designation, width=36, row=5, column=1)
self.add_staff_responsibility_data = get_a_text(master, width=36, height=4, row=6, column=1)
self.add_staff_about_data = get_a_text(master, width=36, height=10, row=7, column=1)
self.add_staff_active_data = get_a_radio(master, text="Active", variable=Active, value=1, row=8, column=1)
self.add_staff_inactive_data = get_a_radio(master, text="Inactive", variable=Active, value=0, row=9, column=1)
self.save_new_staff_button = get_a_button(master, text="Add Staff", row=10, padx=(20, 20), pady=(30, 30))
self.cancel_new_staff_button = get_a_button(master, text="Cancel", row=10, column=1, padx=(20, 20), pady=(30, 30))
self.save_new_staff_button.config(command=staff_button_callback)
self.cancel_new_staff_button.config(command=cancel_new_staff_button_callback)