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
   |  
#! /usr/bin/env python
# -*- coding: Latin-1 -*-
import os, sys
 
from Tkinter import *
import Image
 
class MenuBar(Frame):
    """Barre de menus déroulants"""
    def __init__(self, boss =None):
        Frame.__init__(self, borderwidth =2)
 
        ##### Menu <Fichier> #####
        fileMenu = Menubutton(self, text ='Fichier')
        #fileMenu.grid(row = 0, column = 0)
        fileMenu.pack(side =LEFT)
        # Partie "déroulante" :
        me1 = Menu(fileMenu)
        me1.add_command(label ='Terminer', underline =0, command = boss.quit)
        # Intégration du menu :
        fileMenu.configure(menu = me1)
 
 
class Curseurs(Frame):
    def __init__(self, boss=None):
        Frame.__init__(self)        # constructeur de la classe parente
        self.vR, self.vV, self.vB = -1, -1, -1
        #composante rouge
        Scale(self, length=400, orient=HORIZONTAL, label ='Composante Rouge :',
                troughcolor ='dark grey', sliderlength =20,
                showvalue =0, from_=0, to=255, tickinterval =25,
                command= lambda x, num=1 : updateLabel(x,num)).pack()
        lab1 = Label(self)
        lab1.pack()
        #composante verte
        Scale(self, length=400, orient=HORIZONTAL, label ='Composante Verte :',
                troughcolor ='dark grey', sliderlength =20,
                showvalue =0, from_=0, to=255, tickinterval =25,
                command= lambda x, num=2 : updateLabel(x,num)).pack()
        lab2 = Label(self)
        lab2.pack()
        #composante bleue
        Scale(self, length=400, orient=HORIZONTAL, label ='Composante Bleue :',
                troughcolor ='dark grey', sliderlength =20,
                showvalue =0, from_=0, to=255, tickinterval =25,
                command= lambda x, num=3 : updateLabel(x,num)).pack()
        lab3 = Label(self)
        lab3.pack()
        #on ajoute le bouton pour valider les valeurs choisies
        bouton = Button(self, text = 'Valider les nouvelles valeurs', command= lambda param1=X, param2=Y, param3=self.vR, param4=self.vV, param5=self.vB : validation(param1,param2,param3,param4,param5))
        bouton.pack()
 
        def updateLabel(x, num): #met a jour la valeur de chaque curseur pour l'afficher a l'utilisateur
            if (num == 1):
                lab1.configure(text='Valeur actuelle = ' + str(x))
                self.vR = x
            if (num == 2):
                lab2.configure(text='Valeur actuelle = ' + str(x))
                self.vV = x
            if (num == 3):
                lab3.configure(text='Valeur actuelle = ' + str(x))
                self.vB = x
 
        def validation(X, Y, a, b, c):#modifie les valeurs du pixel
            print 'il faut modifier le pixel en position ('+str(X)+','+str(Y)+') avec les composantes '+str(a)+' '+str(b)+' '+str(c)           
 
class Application(Frame):
    """Application principale"""
    def __init__(self, boss =None):
        Frame.__init__(self)
        self.master.title('test')
        mBar = MenuBar(self)
        mBar.pack()
        self.canevas1 = Canvas(self, bg='light grey', height=500,
                          width=500, borderwidth =2)
        self.canevas1.pack()
        self.canevas1.bind("<Button-3>", self.affich_curseurs)
        self.pack()
 
    def affich_curseurs(self, event):
        X = str(event.x)
        Y = str(event.y)
 
        fen = Tk()
        fra = Curseurs(fen)
        fen.mainloop()
 
if __name__ == '__main__':
    app = Application()
    app.mainloop() | 
Partager