Matlab: Changer couleur selon le choix d'un listBox
Répondre à la discussion
Affichage des résultats 1 à 4 sur 4

Matlab: Changer couleur selon le choix d'un listBox



  1. #1
    invite19a844bd

    Matlab: Changer couleur selon le choix d'un listBox


    ------

    Salut,

    Je veux changer la couleur d'un bouton "Pass" selon le choix du ListBox comme montre le code suivant:

    Code:
    function list_VIN_Callback(hObject, eventdata, handles) 
    if strcmp(get(handles.list_VIN,'String'), '...............< Aucun >.............') 
      
        set(handles.Pass, 'BackgroundColor','red'); 
       
       else 
        set(handles.Pass, 'BackgroundColor','green'); 
        
    end;

    Quand je fais un choix VIN1, VIN2 ou VIN3 la couleur du bouton "Pass" devient verte mais quand je fais le choix "........<Aucun>........." la couleur ne change pas ou reste verte? Pourriez vous m'aider svp?

    Merci


    lis_box1.PNG

    list_box2.PNG

    -----

  2. #2
    Antoane
    Responsable technique

    Re : Question Matlab: Changer couleur selon le choix d'un listBox

    Bonjour,

    Peux-tu poster ici le code complet, pour qu'on puisse l'executer et voir ce qui advient ?

    Sinon, met-toi en mode débug et observe l'état des variables à chaque ligne, pour voir ce qui est conforme ou non aux attentes.

    Tu programme pour quelle version de matlab ?
    Deux pattes c'est une diode, trois pattes c'est un transistor, quatre pattes c'est une vache.

  3. #3
    invite19a844bd

    Re : Matlab: Changer couleur selon le choix d'un listBox

    Code:
    function varargout = ListBOx(varargin)
    % LISTBOX MATLAB code for ListBOx.fig
    % LISTBOX, by itself, creates a new LISTBOX or raises the existing
    % singleton*.
    %
    % H = LISTBOX returns the handle to a new LISTBOX or the handle to
    % the existing singleton*.
    %
    % LISTBOX('CALLBACK',hObject,eventData,handles,...) calls the local
    % function named CALLBACK in LISTBOX.M with the given input arguments.
    %
    % LISTBOX('Property','Value',...) creates a new LISTBOX or raises the
    % existing singleton*. Starting from the left, property value pairs are
    % applied to the GUI before ListBOx_OpeningFcn gets called. An
    % unrecognized property name or invalid value makes property application
    % stop. All inputs are passed to ListBOx_OpeningFcn via varargin.
    %
    % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
    % instance to run (singleton)".
    %
    % See also: GUIDE, GUIDATA, GUIHANDLES
    % Edit the above text to modify the response to help ListBOx
    % Last Modified by GUIDE v2.5 06-Jun-2017 13:06:22
    % Begin initialization code - DO NOT EDIT
    gui_Singleton = 1;
    gui_State = struct('gui_Name', mfilename, ...
    'gui_Singleton', gui_Singleton, ...
    'gui_OpeningFcn', @ListBOx_OpeningFcn, ...
    'gui_OutputFcn', @ListBOx_OutputFcn, ...
    'gui_LayoutFcn', [] , ...
    'gui_Callback', []);
    if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
    end
    if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
    else
    gui_mainfcn(gui_State, varargin{:});
    end
    % End initialization code - DO NOT EDIT
    % --- Executes just before ListBOx is made visible.
    function ListBOx_OpeningFcn(hObject, eventdata, handles, varargin)
    % This function has no output args, see OutputFcn.
    % hObject handle to figure
    % eventdata reserved - to be defined in a future version of MATLAB
    % handles structure with handles and user data (see GUIDATA)
    % varargin command line arguments to ListBOx (see VARARGIN)
    % Choose default command line output for ListBOx
    handles.output = hObject;
    % Update handles structure
    guidata(hObject, handles);
    % UIWAIT makes ListBOx wait for user response (see UIRESUME)
    % uiwait(handles.figure1);
    % --- Outputs from this function are returned to the command line.
    function varargout = ListBOx_OutputFcn(hObject, eventdata, handles) 
    % varargout cell array for returning output args (see VARARGOUT);
    % hObject handle to figure
    % eventdata reserved - to be defined in a future version of MATLAB
    % handles structure with handles and user data (see GUIDATA)
    % Get default command line output from handles structure
    varargout{1} = handles.output;
    % --- Executes on selection change in list_VIN.
    function list_VIN_Callback(hObject, eventdata, handles)
    if strcmp(get(handles.list_VIN,'String'), '...............< Aucun >.............')
    set(handles.Pass, 'BackgroundColor','red');
    else
    set(handles.Pass, 'BackgroundColor','green');
    end;
    % --- Executes during object creation, after setting all properties.
    function list_VIN_CreateFcn(hObject, eventdata, handles)
    % hObject handle to list_VIN (see GCBO)
    % eventdata reserved - to be defined in a future version of MATLAB
    % handles empty - handles not created until after all CreateFcns called
    % Hint: listbox controls usually have a white background on Windows.
    % See ISPC and COMPUTER.
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
    end
    % --- Executes on button press in Pass.
    function Pass_Callback(hObject, eventdata, handles)
    % hObject handle to Pass (see GCBO)
    % eventdata reserved - to be defined in a future version of MATLAB
    % handles structure with handles and user data (see GUIDATA)
    % --- Executes on button press in Not_Pass.
    function Not_Pass_Callback(hObject, eventdata, handles)
    % hObject handle to Not_Pass (see GCBO)
    % eventdata reserved - to be defined in a future version of MATLAB
    % handles structure with handles and user data (see GUIDATA)
    Voici le code.

    Matlab version 2013

  4. #4
    Antoane
    Responsable technique

    Re : Matlab: Changer couleur selon le choix d'un listBox

    Bonjour,

    Je t'invite à te mettre en mode débug, en particulier à partir de la ligne :
    >> if strcmp(get(handles.list_VIN,'S tring'), '...............< Aucun >.............')
    et à observer l'état des variables à chaque ligne, pour voir ce qui est conforme ou non aux attentes.

    Car le code que tu as envoyé n'est pas simulable en l'état.

    Edit : je déplace la discussion dans un forum plus adapté.
    Dernière modification par Antoane ; 07/06/2017 à 15h23.
    Deux pattes c'est une diode, trois pattes c'est un transistor, quatre pattes c'est une vache.

  5. A voir en vidéo sur Futura

Discussions similaires

  1. Logiciel de gestion de choix de stage (ou autres choix selon des voeux)
    Par invitec187ecaf dans le forum Programmation et langages, Algorithmique
    Réponses: 6
    Dernier message: 07/10/2014, 18h12
  2. Gestion de choix de stage (ou autres choix selon des voeux)
    Par invitec187ecaf dans le forum Mathématiques du supérieur
    Réponses: 1
    Dernier message: 30/09/2014, 14h20
  3. Couleur du diiode selon solvants
    Par aNyFuTuRe- dans le forum Chimie
    Réponses: 1
    Dernier message: 09/12/2010, 20h25
  4. Couleur du ciel selon la couleur du soleil
    Par invite7def40fb dans le forum Archives
    Réponses: 7
    Dernier message: 25/07/2010, 21h06
  5. Couleur d'un item dans listbox en VB 6.3
    Par inviteb2917e5f dans le forum Logiciel - Software - Open Source
    Réponses: 1
    Dernier message: 15/03/2009, 17h00