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
| class MicroCalculette(Frame):
def __init__(self, parent=None):
if not parent: parent = Tk()
Frame.__init__(self, parent)
self.ecran = Label(self, bg = "black", anchor = E, fg = "white", text = "0", width = 16)
self.ecran.grid(row = 0, column = 0, columnspan = 4, ipadx = 2, ipady = 2)
def button (text,width,height,row,column,rowspan=1,columnspan=1):
def func ( x ): print x
bouton = Button( self,
anchor = CENTER,
text = text,
command = lambda : func( text ),
width = width ,
height = height )
bouton.grid( row = row ,
column = column ,
rowspan = rowspan ,
columnspan = columnspan )
button( 'C',3,1,1,0 )
button( '/',3,1,1,1 )
button( '*',3,1,1,2 )
button( '-',3,1,1,3 )
button( '7',3,1,2,0 )
button( '8',3,1,2,1 )
button( '9',3,1,2,2 )
button( '+',3,3,2,3,2 )
button( '4',3,1,3,0 )
button( '5',3,1,3,1 )
button( '6',3,1,3,2 )
button( '1',3,1,4,0 )
button( '2',3,1,4,1 )
button( '3',3,1,4,2 )
button( '=',3,3,4,3,2 )
button( '0',7,1,5,0,columnspan=2 )
button( '.',3,1,5,2 )
self.pack()
parent.mainloop() |
Partager