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
| # -*- coding: utf-8 -*-
from tkinter import Frame, Tk, Toplevel, Entry, LEFT, TOP
import tkinter.ttk as ttk
import os
def calculate(entries, win):
somme = 0
for nb in entries:
if nb.get() != '':
somme += int(nb.get())
print('calculation... somme='+str(somme))
def generateEntry(win, k, entryList, btList, btCal):
newEntryList = []
for i in range(0, len(entryList)):
entryList[i].grid_forget()
for i in range (1, k+1):
e = Entry(win, width=5)
e.grid(row=1, column=i, padx=5, pady=5)#ROW=1 ET COLUMN=1 FONCTIONNE PAS ??
newEntryList.append(e)
for i in range(0, 10):
btList[i].config(comman=lambda n=i+1, eList=newEntryList, bList=btList :generateEntry(win, n, eList, bList, btCal))
btCal.config(command=lambda: calculate(newEntryList, win))
btCal.grid(row=1, column=0)
def openMi3(root):
winMi3 = Toplevel(root)
#winMi3.columnconfigure(0, weight=200)
#winMi3.rowconfigure(0, weight=10)
entryList = []
boutonList = []
btCal = ttk.Button(winMi3, text="Calculate", width=15)
ttk.Label(winMi3, width=35, text="Please click on button: ", anchor="center").grid(sticky='nw', row=0, column=0, padx=5, pady=5)
for k in range (1, 11):
bouton = ttk.Button(winMi3, text=k, width=5)
boutonList.append(bouton)
bouton.config(comman=lambda n=k, eList=entryList, btList=boutonList :generateEntry(winMi3, n, eList, btList, btCal))
bouton.grid(sticky='ne', row=0, column=k-1, padx=5, pady=5)
#PROBLEME : PAS D'AFFICHAGE
labelIn = ttk.Label(root, text="IN", width=10, anchor="center")
labelIn.grid(sticky='new', row=2, column=2, padx=5, pady=5, columnspan=2)
boutonOk = ttk.Button(root, text="un", width=10)
boutonOk.grid(sticky='new', row=3, column=1, padx=5, pady=5)
boutonOk = ttk.Button(root, text="deux", width=10)
boutonOk.grid(sticky='new', row=3, column=2, padx=5, pady=5)
boutonOk = ttk.Button(root, text="trois", width=10)
boutonOk.grid(sticky='new', row=3, column=3, padx=5, pady=5)
boutonOk = ttk.Button(root, text="quatre", width=10)
boutonOk.grid(sticky='new', row=3, column=4, padx=5, pady=5)
labelOut = ttk.Label(root, text="OUT", width=10, anchor="center")
labelOut.grid(sticky='ne', row=2, column=2, padx=5, pady=5, columnspan=2)
#ajouter 4 boutons du out
boutonOk = ttk.Button(root, text="VALIDER", width=10, comman=lambda: generateEntry(1, 2, 3, 4, 5))
boutonOk.grid(sticky='ne', row=4, column=5, padx=5, pady=5, columnspan=2)
#winMi3.geometry("450x200+300+100")
def main():
root = Tk()
ex = Example(root)
root.geometry("5x5+0+0")
root.mainloop()
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
openMi3(self)
if __name__ == '__main__':
main() |
Partager