Hello Dear Programmers.
I have a "Tuple Object is not callable" Errror and I need your help.
File "D:\Miniconda3\envs\ml_env\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "D:\Desktop\Gestion de projet mayadigital\inter_admin.py", line 242, in valider_suppression
for i in self.employes():
TypeError: 'tuple' object is not callable
I am creating a small software linked to a database. One of the options allows the admin to delete one or multiple users.
To do this I created a Listbox inside a Tkinter Instance. After the admin selected the users to delete, I want to display the list of theses users for confirmation.
This is where I have my problem:
I need to know which are the item clicked on the Listbox, so I use this method:
self.employes=self.liste_employes.curselection()
But when I want to use self.employes thanks to the following code, I get the error.
for i in self.employes():
self.employes_a_supprimer.insert(i, rows[i][1]+' '+rows[i][2])
self.employes_a_supprimer.pack()
This is an extract of my code:
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 16 21:30:12 2020
@author: cheri
"""
from tkinter import *
import bdd_access as ba
class Interface(Frame):
def __init__(self, fenetre, **kwargs):
"""Initialisation de la fenêtre"""
Frame.__init__(self, fenetre, width=768, height=576, **kwargs)
self.pack(fill=BOTH)
self.menu()
def supprimer(self):
self.destroy_menu()
rows=ba.liste_employes()
self.tx_selection=Label(self, text="Veuillez choisir le(s) employé(s) à supprimer.")
self.tx_selection.pack()
self.liste_employes=Listbox(self,selectmode=BROWSE)
for i in range (0,len(rows)):
self.liste_employes.insert(i,rows[i][1]+' '+rows[i][2])
self.liste_employes.pack()
self.button_valider=Button(self,text="Valider",command=self.valider_suppression)
self.button_valider.pack()
def destroy_supprimer(self):
self.title.destroy()
self.tx_selection.destroy()
self.liste_employes.destroy()
self.button_valider.destroy()
self.button_annuler.destroy()
def valider_suppression(self):
self.employes=self.liste_employes.curselection()
self.destroy_supprimer()
self.title=Label(self,text="Veuillez confirmer que vous souhaitez bien supprimer les employés suivants:")
self.title.pack()
self.employes_a_supprimer=Listbox(self, selectmode=SINGLE)
print(self.employes)
print(type(self.employes))
for i in self.employes():
self.employes_a_supprimer.insert(i, rows[i][1]+' '+rows[i][2])
self.employes_a_supprimer.pack()
self.button_confirmer=Button(self,text="Confirmer",command=self.suppression_bdd)
self.button_confirmer.pack()
self.button_retour=Button(self,text="Modifier la selection",command=retour_suppression)
self.button_retour.pack()
self.button_annuler=Button(self,text="Annuler l'opération",command=self.valider_supprimer_to_menu)
self.button_annuler.pack()
def menu(self):
# Création de nos widgets
self.title = Label(self, text="Bienvenue sur l'interface d'administration, que souhaitez-vous faire?")
self.title.pack()
self.bouton_affichage_logins= Button(self,text="Affichage de tous les logins et mots de passe",command=self.affichage)
self.bouton_affichage_logins.pack()
self.bouton_ajout=Button(self,text="Ajouter un employé au système",command=self.ajout)
self.bouton_ajout.pack()
self.bouton_suppression=Button(self,text="Supprimer un employé du système",command=self.supprimer)
self.bouton_suppression.pack()
self.bouton_changer=Button(self,text="Changer un mot de passe",command=self.changer)
self.bouton_changer.pack()
self.bouton_quitter = Button(self, text="Quitter", command=self.destroy)
self.bouton_quitter.pack()
def destroy_menu(self):
self.title.destroy()
self.bouton_affichage_logins.destroy()
self.bouton_ajout.destroy()
self.bouton_suppression.destroy()
self.bouton_changer.destroy()
self.bouton_quitter.destroy()
Yes, this is a french code;)
Supprimer=Delete
Valider_Suppression=Confirm_suppression
I hope I've made myself clear enough to be understood
Thanks a lot for the future answers on my post.
The answer is an error in my code I could not see, thanks to @bryan-oakley for his help.
The right piece of code is:
for i in self.employes: #Without parenthesis
self.employes_a_supprimer.insert(i, rows[i][1]+' '+rows[i][2])
self.employes_a_supprimer.pack()
Problem solved !
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.