Partage
  • Partager sur Facebook
  • Partager sur Twitter

frame clignotante

Python3 - tkinter

Sujet résolu
    18 novembre 2019 à 14:00:12

    Bonjour à Tous,

    Je me lance sur Python depuis quelques semaines, pour un projet professionnel.

    J'ai un soucis et donc, besoin de vos talents.

    Je veux faire message d'alarme que j'aimerais faire clignoter.

    J'ai trouvé sur les différentes discussions, une petite fonction mais mon soucis c'est que la fenêtre se déplace.

    Voici mon bout de code correspondant:

    Label_status = 'place'


    def alarm():
    global Label_status
    alarm_button = Label(al_frame, text="Alarm, please check ink and hydraulic circuit", font=("Courrier", 20), bg='#E42922',)
    alarm_button.pack(side=BOTTOM, fill=X)

    if Label_status == 'place':
    alarm_button.pack_forget()
    Label_status = 'not_place'
    # Sinon
    else:
    alarm_button.pack()
    Label_status = 'place'
    al_frame.after(100, alarm) # Et on boucle tout les 100ms



    # test affichage alarm
    test_button = Button(esc_frame, text="test alarm", font=("Courrier", 15), bg='#ED762D', fg='white', bd=2, command=alarm)
    test_button.pack(fill=X)

    bon vous moquez pas, je débute :)

    Merci de votre aide

    Bonne Journée

    Chris

    • Partager sur Facebook
    • Partager sur Twitter
      18 novembre 2019 à 14:53:38

      Bonjour, Le code n'est pas complet, donne le entier sinon on ne peut pas le tester. Et tu ne dis pas le problème que tu rencontres ni quel est le message d'erreur. Par ailleurs, tu n'as pas choisis les bonnes balises (celles pour Python qui ne sont pas comme ça)

      • Partager sur Facebook
      • Partager sur Twitter
        18 novembre 2019 à 14:57:31

        Merci de ta réponse rapide.

        Voici le code complet

        from tkinter import *
        import tkinter
        from tkinter import Label
        Root_window = Tk()
        Root_window.title("MCS-CONVATEC")
        Root_window.geometry("1080x720")
        Root_window.minsize(780, 360)
        Root_window.iconbitmap("LOGO-MCS-ico-2.ico")
        Root_window.config(background='#A29EA4')

        Label_title = Label(Root_window, text="Convatec Ink Filling System", font=("Calibri", 20), bg='#A29EA4', fg='white')
        Label_title.pack()

        Label_subtitle = Label(Root_window, text="Ink-Low status", font=("Calibri", 15), bg='#A29EA4', fg='white')
        Label_subtitle.pack()
        # creation bouton quitter
        esc_frame = Frame(Root_window, relief=SUNKEN)
        esc_frame.pack(anchor='e')
        esc_button = Button(esc_frame, text="Quit", font=("Courrier", 15), bg='#5F6062', fg='white', bd=2, command=quit)
        esc_button.pack(fill=X)

        # Creation des textes en dessus des icons

        Text_frame = Button(Root_window, text="Head#1 Head#2 Head#3 Head#4 Head#5 Head#6", font=("Helvetica", 12), bg='#5F6062', fg='white', bd=0)
        Text_frame.pack(anchor='n')

        # Creation des images ok-inklow dans une frame

        il_frame = Frame(Root_window, relief=GROOVE)
        il_frame.pack()

        # creation frame pour le msg d'alarme

        al_frame = Frame(Root_window, width=20, relief=GROOVE)
        al_frame.pack(side=BOTTOM)

        # curseur de réglage tempo
        scale_tempo = tkinter.Scale(Root_window, from_=10, to=100, orient=HORIZONTAL)
        scale_tempo.pack(side=BOTTOM, pady=80, padx=50, anchor='e')

        label_adjust = LabelFrame(Root_window, text=" adjust ink filling tempo", font=("ArialBold", 15), bg='#E42922',bd=2, relief=SUNKEN)
        label_adjust.pack(anchor='s')

        # fonction pour affichage frame alarme

        Label_status = 'place'


        def alarm():
        global Label_status
        alarm_button = Label(al_frame, text="Alarm, please check ink and hydraulic circuit", font=("Courrier", 20), bg='#E42922',)
        alarm_button.pack(side=BOTTOM, fill=X)

        if Label_status == 'place':
        alarm_button.pack_forget()
        Label_status = 'not_place'
        # Sinon
        else:
        alarm_button.pack()
        Label_status = 'place'
        al_frame.after(100, alarm) # Et on boucle tout les 100ms



        # test affichage alarm
        test_button = Button(esc_frame, text="test alarm", font=("Courrier", 15), bg='#ED762D', fg='white', bd=2, command=alarm)
        test_button.pack(fill=X)

        width = 100
        height = 200
        image_1 = PhotoImage(file="ok.png"). zoom(10).subsample(35)
        canvas = Canvas(il_frame, width=width, height=height, bg='#A29EA4', bd=0, highlightthickness=0)
        canvas.create_image(width/2, height/2, image=image_1)
        canvas.grid(row=0, column=0, sticky='w')

        width = 100
        height = 200
        image_2 = PhotoImage(file="ok.png"). zoom(10).subsample(35)
        canvas = Canvas(il_frame, width=width, height=height, bg='#A29EA4', bd=0, highlightthickness=0)
        canvas.create_image(width/2, height/2, image=image_2)
        canvas.grid(row=0, column=1, sticky='w')

        width = 100
        height = 200
        image_3 = PhotoImage(file="ok.png"). zoom(10).subsample(35)
        canvas = Canvas(il_frame, width=width, height=height, bg='#A29EA4', bd=0, highlightthickness=0)
        canvas.create_image(width/2, height/2, image=image_3)
        canvas.grid(row=0, column=2, sticky='w')

        width = 100
        height = 200
        image_4 = PhotoImage(file="ok.png"). zoom(10).subsample(35)
        canvas = Canvas(il_frame, width=width, height=height, bg='#A29EA4', bd=0, highlightthickness=0)
        canvas.create_image(width/2, height/2, image=image_4)
        canvas.grid(row=0, column=3, sticky='w')

        width = 100
        height = 200
        image_5 = PhotoImage(file="ok.png"). zoom(10).subsample(35)
        canvas = Canvas(il_frame, width=width, height=height, bg='#A29EA4', bd=0, highlightthickness=0)
        canvas.create_image(width/2, height/2, image=image_5)
        canvas.grid(row=0, column=4, sticky='w')

        width = 100
        height = 200
        image_6 = PhotoImage(file="cancel.png"). zoom(10).subsample(35)
        canvas = Canvas(il_frame, width=width, height=height, bg='#A29EA4', bd=0, highlightthickness=0)
        canvas.create_image(width/2, height/2, image=image_6)
        canvas.grid(row=0, column=5, sticky='w')

        Root_window.mainloop()

        par contre, je n'ai aucun message d'erreur.

        Juste que ma fenêtre ne clignote pas mais se répète.

        Merci

        • Partager sur Facebook
        • Partager sur Twitter
          18 novembre 2019 à 15:31:48

          Je ne vois pas comment tu pourrais ne pas avoir de message d'erreur avec ce code vu que ton global est à la mauvaise indentation :

          def alarm():
          global Label_status
              alarm_button = Label(al_frame, text="Alarm, please check ink and hydraulic circuit", font=("Courrier", 20), bg='#E42922',)
              alarm_button.pack(side=BOTTOM, fill=X)
          
          if Label_status == 'place':
                  alarm_button.pack_forget()
                  Label_status = 'not_place'
          # Sinon
          else:
                  alarm_button.pack()
                  Label_status = 'place'
          al_frame.after(100, alarm)         # Et on boucle tout les 100ms
          
          • Partager sur Facebook
          • Partager sur Twitter
            18 novembre 2019 à 15:35:11

            je ne sais pas mais je n'ai pas d'erreur!

            la fenêtre s'affiche, puis une autre dessus la précédente etc...

            on est bien d'accord que le copier/coller n'a pas respecté les tabulations?

            -
            Edité par Chris-vm 18 novembre 2019 à 15:39:35

            • Partager sur Facebook
            • Partager sur Twitter
              18 novembre 2019 à 15:41:11

              Voici ton code (dans des balises plus lisibles) :

              from tkinter import *
              import tkinter
              from tkinter import Label
              Root_window = Tk()
              Root_window.title("MCS-CONVATEC")
              Root_window.geometry("1080x720")
              Root_window.minsize(780, 360)
              Root_window.config(background='#A29EA4')
              
              Label_title = Label(Root_window, text="Convatec Ink Filling System", font=("Calibri", 20), bg='#A29EA4', fg='white')
              Label_title.pack()
              
              Label_subtitle = Label(Root_window, text="Ink-Low status", font=("Calibri", 15), bg='#A29EA4', fg='white')
              Label_subtitle.pack()
              # creation bouton quitter
              esc_frame = Frame(Root_window, relief=SUNKEN)
              esc_frame.pack(anchor='e')
              esc_button = Button(esc_frame, text="Quit", font=("Courrier", 15), bg='#5F6062', fg='white', bd=2, command=quit)
              esc_button.pack(fill=X)
              
              # Creation des textes en dessus des icons
              
              Text_frame = Button(Root_window, text="Head#1 Head#2 Head#3 Head#4 Head#5 Head#6", font=("Helvetica", 12), bg='#5F6062', fg='white', bd=0)
              Text_frame.pack(anchor='n')
              
              # Creation des images ok-inklow dans une frame
              
              il_frame = Frame(Root_window, relief=GROOVE)
              il_frame.pack()
              
              # creation frame pour le msg d'alarme
              
              al_frame = Frame(Root_window, width=20, relief=GROOVE)
              al_frame.pack(side=BOTTOM)
              
              # curseur de réglage tempo
              scale_tempo = tkinter.Scale(Root_window, from_=10, to=100, orient=HORIZONTAL)
              scale_tempo.pack(side=BOTTOM, pady=80, padx=50, anchor='e')
              
              label_adjust = LabelFrame(Root_window, text=" adjust ink filling tempo", font=("ArialBold", 15), bg='#E42922',bd=2, relief=SUNKEN)
              label_adjust.pack(anchor='s')
              
              # fonction pour affichage frame alarme
              
              Label_status = 'place'
              
              
              def alarm():
              global Label_status
                  alarm_button = Label(al_frame, text="Alarm, please check ink and hydraulic circuit", font=("Courrier", 20), bg='#E42922',)
                  alarm_button.pack(side=BOTTOM, fill=X)
              
              if Label_status == 'place':
                      alarm_button.pack_forget()
                      Label_status = 'not_place'
              # Sinon
              else:
                      alarm_button.pack()
                      Label_status = 'place'
              al_frame.after(100, alarm)         # Et on boucle tout les 100ms
              
              
              
              # test affichage alarm
              test_button = Button(esc_frame, text="test alarm", font=("Courrier", 15), bg='#ED762D', fg='white', bd=2, command=alarm)
              test_button.pack(fill=X)
              
              width = 100
              height = 200
              image_1 = PhotoImage(file="a.png"). zoom(10).subsample(35)
              canvas = Canvas(il_frame, width=width, height=height, bg='#A29EA4', bd=0, highlightthickness=0)
              canvas.create_image(width/2, height/2, image=image_1)
              canvas.grid(row=0, column=0, sticky='w')
              
              width = 100
              height = 200
              image_2 = PhotoImage(file="a.png"). zoom(10).subsample(35)
              canvas = Canvas(il_frame, width=width, height=height, bg='#A29EA4', bd=0, highlightthickness=0)
              canvas.create_image(width/2, height/2, image=image_2)
              canvas.grid(row=0, column=1, sticky='w')
              
              width = 100
              height = 200
              image_3 = PhotoImage(file="a.png"). zoom(10).subsample(35)
              canvas = Canvas(il_frame, width=width, height=height, bg='#A29EA4', bd=0, highlightthickness=0)
              canvas.create_image(width/2, height/2, image=image_3)
              canvas.grid(row=0, column=2, sticky='w')
              
              width = 100
              height = 200
              image_4 = PhotoImage(file="a.png"). zoom(10).subsample(35)
              canvas = Canvas(il_frame, width=width, height=height, bg='#A29EA4', bd=0, highlightthickness=0)
              canvas.create_image(width/2, height/2, image=image_4)
              canvas.grid(row=0, column=3, sticky='w')
              
              width = 100
              height = 200
              image_5 = PhotoImage(file="a.png"). zoom(10).subsample(35)
              canvas = Canvas(il_frame, width=width, height=height, bg='#A29EA4', bd=0, highlightthickness=0)
              canvas.create_image(width/2, height/2, image=image_5)
              canvas.grid(row=0, column=4, sticky='w')
              
              width = 100
              height = 200
              image_6 = PhotoImage(file="cancel.png"). zoom(10).subsample(35)
              canvas = Canvas(il_frame, width=width, height=height, bg='#A29EA4', bd=0, highlightthickness=0)
              canvas.create_image(width/2, height/2, image=image_6)
              canvas.grid(row=0, column=5, sticky='w')
              
              Root_window.mainloop()
              

              et voici la réponse quand je lance :

                File "clignote.py", line 49
                  global Label_status
                       ^
              IndentationError: expected an indented block
              



              EDIT 

              Et même si je règle ce problème, il y a d'autres erreurs.

              -
              Edité par PascalOrtiz 18 novembre 2019 à 15:43:50

              • Partager sur Facebook
              • Partager sur Twitter
                18 novembre 2019 à 15:45:06

                par contre, on est d'accord que mon copier/coller n'a pas respecter les tabulations :)

                en fait, je débute et c'est mon premier post

                Dans mon code, le global Label_status ainsi que le if et else, sont dans la fonction alarm()

                Voilà ce que j'ai sur la console après avoir lancer le programme et cliqué plusieurs fois sur mon bouton test alarm

                C:\Users\Christophe.ALE\AppData\Local\Programs\Python\Python38\python.exe C:/Users/Christophe.ALE/PycharmProjects/convatec-chb/interface-convatec.py

                Process finished with exit code 0

                pas d'erreur...

                -
                Edité par Chris-vm 18 novembre 2019 à 15:50:49

                • Partager sur Facebook
                • Partager sur Twitter
                  18 novembre 2019 à 16:02:01

                  Chris-vm a écrit:

                  par contre, on est d'accord que mon copier/coller n'a pas respecter les tabulations :)


                  C'est pour ça que je t'ai dit dans mon premier message d'utiliser les bonnes balises. Un code Python mal indenté  est ininterprétable.

                  EDIT

                  Pour les balises, utilise Editeur et pas Makdown et clique sur le bouton </>

                  -
                  Edité par PascalOrtiz 18 novembre 2019 à 16:03:25

                  • Partager sur Facebook
                  • Partager sur Twitter
                    18 novembre 2019 à 16:33:21

                    ok

                    sinon aurais-tu un exemple de de code pour une fenêtre clignotante pour Tkinter?

                    -
                    Edité par Chris-vm 18 novembre 2019 à 16:36:00

                    • Partager sur Facebook
                    • Partager sur Twitter
                      18 novembre 2019 à 16:41:16

                      Je n'ai pas de code pour une fenêtre clignotante mais c'est facilement réalisable en faisant une animation avec la méthode after
                      • Partager sur Facebook
                      • Partager sur Twitter
                        18 novembre 2019 à 16:58:58

                        ok merci Pascal!

                        je ferme le post même si ma fenêtre clignote toujours pas :)

                        Bonne soirée

                        • Partager sur Facebook
                        • Partager sur Twitter

                        frame clignotante

                        × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
                        × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
                        • Editeur
                        • Markdown