Bonjour,
Afin de pouvoir réutiliser les mêmes réglages pour des tableaux Treeview, j ai voulu créer une classe tableau pour l'utiliser ensuite avec 3 tableaux dans une même Frame en utilisant un grid() mais malheureusement cela ne marche pas. Pouvez vous m'aider et m'expliquer pourquoi ça ne marche pas?
En vous remerciant d'avance.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 
import tkinter as tk
from tkinter import *
from tkinter import ttk
 
 
montitre1=['Analyte','unité' ,'Contrôle', 'LA', 'Résultat', 'Cible' ,'Biais%' ,'CV%' ,'Note', 'z-score', 'Cible', 'Biais%' ,'CV%' ,'Note' ,'z-score']
montitre2=['c1','c2','c3']
montitre3=['choix1','choix2']
 
class montableau(ttk.Frame):
    def __init__(self,root,mestitres):
        super().__init__(root,mestitres)
        self.titre=mestitres
        self.parent=root
        self.tableau1 = ttk.Treeview(self.parent, columns=tuple(self.titre), show='headings', selectmode='extended',
                                 takefocus=True)
        self.tableau1['show'] = 'headings'
        for i in range(len(mestitres)):
            self.tableau1.heading(i, text=mestitres[i])
            if (i == 0):
                self.tableau1.column(i, minwidth=0, width=120, stretch=NO)
            else:
                self.tableau1.column(i, minwidth=0, width=80, stretch=NO)
 
root = Tk()
root.geometry("1250x700")
root_frame = Frame(root)
root_frame.pack()
 
tab1=montableau(root_frame,montitre1)
tab2=montableau(root_frame,montitre2)
tab3=montableau(root_frame,montitre3)
 
tab1.grid(row=0, column=0)
tab2.grid(row=0, column=3)
tab3.grid(row=5, column=2)
 
root.mainloop()
Voici mon message d'erreur:
"
Traceback (most recent call last):
File "C:\Python241121\T14_canny\T14_canny\essaifenetre1.py", line 30, in <module>
tab1=montableau(root_frame,montitre1)
File "C:\Python241121\T14_canny\T14_canny\essaifenetre1.py", line 12, in __init__
super().__init__(root,mestitres)
TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given
"
et donc je ne vois pas ou est le problème :
- j'indique bien le paramétrage du root et l'utilisation d'une liste() mais peut être que je ne peux pas utiliser une classe sans affichage dans celle ci . Mes compétences en python étant très limitées j'aurai souhaité vos avis aussi bien sur les erreurs que sur l'utilisation d'une classe pour fabriquer un widget customisé!"
Merci pour vos réponses.