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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
| class Interface(Frame):
def __init__(self, fenetre, **kwargs):
Frame.__init__(self, fenetre, width=1500, height=1000, **kwargs)
self.pack(fill=BOTH)
"""
Saisie nouvelle CATEGORIE
"""
self.saisieNewCat = Entry(self)
self.saisieNewCat.insert(0, 'Nouvelle catégorie')
self.saisieNewCat.bind('<Return>', self.addCatS)
self.saisieNewCat.pack()
"""
Saisie nouveau SPLIT
"""
self.saisieNewSplit = Entry(self)
self.saisieNewSplit.insert(0, 'Nouveau split')
self.saisieNewSplit.bind('<Return>', self.addSplitS)
self.saisieNewSplit.pack()
"""
Liste des CATEGORIES
"""
self.choiceCatVar = StringVar()
self.choicesCat = list()
for value in Categorie.instances:
self.choicesCat.append(value.name)
self.choiceCatVar.set(self.choicesCat[0])
self.catChoiceBox = OptionMenu(self, self.choiceCatVar, *self.choicesCat,command = self.changeListbox)
self.catChoiceBox.pack()
"""
Liste des SPLITS
"""
# Scrollbar
self.splitsScrollbar = Scrollbar(self)
self.splitsScrollbar.pack(side=RIGHT, fill=Y)
# Listbox
self.splitsListbox = Listbox(self)
self.splitsListbox.pack()
# Attach listbox to scrollbar
self.splitsListbox.config(yscrollcommand=self.splitsScrollbar.set)
self.splitsScrollbar.config(command=self.splitsListbox.yview)
self.setupListbox()
"""
Bouton ajout de CATEGORIES
"""
self.addCatButton = Button(None)
self.addCatButton.config(text='Ajouter catégorie',command=self.addCatB)
self.addCatButton.pack()
"""
Bouton ajout de SPLITS
"""
self.addSplitButton = Button(None)
self.addSplitButton.config(text='Ajouter split',command=self.addSplitB)
self.addSplitButton.pack()
"""
Bouton lancement bot
"""
self.launchBotButton = Button(None)
self.launchBotButton.config(text='Lancer le bot',command=self.launchBot)
self.launchBotButton.pack()
# For Return's binding
def addCatS(self,e):
self.choiceCatVar.set('')
globals()[self.saisieNewCat.get()] = Categorie(self.saisieNewCat.get())
self.choicesCat.append(Categorie.instances[-1].name)
self.catChoiceBox['menu'].add_command(label=self.choicesCat[-1], command=tk._setit(self.choiceCatVar, self.choicesCat[-1]))
# For button
def addCatB(self):
globals()[self.saisieNewCat.get()] = Categorie(self.saisieNewCat.get())
self.choicesCat.append(Categorie.instances[-1].name)
self.catChoiceBox['menu'].add_command(label=self.choicesCat[-1], command=tk._setit(self.choiceCatVar, self.choicesCat[-1]))
def addSplitS(self,e):
globals()[self.choiceCatVar.get()].liste_Splits.append(self.saisieNewSplit.get())
self.splitsListbox.insert(END,globals()[self.choiceCatVar.get()].liste_Splits[-1])
def addSplitB(self):
globals()[self.choiceCatVar.get()].liste_Splits.append(self.saisieNewSplit.get())
self.splitsListbox.insert(END,globals()[self.choiceCatVar.get()].liste_Splits[-1])
def setupListbox(self):
splits = globals()[self.choiceCatVar.get()].liste_Splits
for value in splits:
self.splitsListbox.insert(END,value)
def changeListbox(self,e):
self.splitsListbox.delete(0,END)
splits = globals()[self.choiceCatVar.get()].liste_Splits
for value in splits:
self.splitsListbox.insert(END,value)
def launchBot(self):
print("test")
class Categorie():
instances=[]
def __init__(self,name):
self.name = name
self.liste_Splits = list()
self.instances.append(self)
def addSplit(self,split):
self.liste_Splits.append(split)
AD = Categorie("AD")
for x in range(1,10):
AD.liste_Splits.append(x)
fenetre = Tk()
interface = Interface(fenetre)
interface.mainloop() |
Partager