IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Tkinter Python Discussion :

Infobulle qui suis le curseur


Sujet :

Tkinter Python

  1. #1
    Membre régulier Avatar de Mysti¢
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    155
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 155
    Points : 116
    Points
    116
    Par défaut Infobulle qui suis le curseur
    Bonjour, je cherche a realiser une info bulle qui suit le curseur de la souris quand on est dans une zone predefinie, un peu comme certaines infobulles javascript qu'on voit un peu partout.

    J'ai teste un programme que j'ai trouve dans les forums.
    Mais premierement, l'infobulle est "fixe" et sous FreeBSD le programme se lance correctement mais j'ai pas d'affichage (pas du tout de fenetre Tk).

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    # -*- coding: ISO-8859-1 -*-
    import Tkinter as tk
     
    class infoBulle(tk.Toplevel):
    	def __init__(self,parent=None,texte='',temps=1000):
    		tk.Toplevel.__init__(self,parent,bd=1,bg='black')
    		self.tps=temps
    		self.parent=parent
    		self.withdraw()
    		self.overrideredirect(1)
    		self.transient()     
    		l=tk.Label(self,text=texte,bg="yellow",justify='left')
    		l.update_idletasks()
    		l.pack()
    		l.update_idletasks()
    		self.tipwidth = l.winfo_width()
    		self.tipheight = l.winfo_height()
    		self.parent.bind('<Enter>',self.delai)
    		self.parent.bind('<Button-1>',self.efface)
    		self.parent.bind('<Leave>',self.efface)
    	def delai(self,event):
    		self.action=self.parent.after(self.tps,self.affiche)
    	def affiche(self):
    		self.update_idletasks()
    		posX = self.parent.winfo_rootx()+self.parent.winfo_width()
    		posY = self.parent.winfo_rooty()+self.parent.winfo_height()
    		if posX + self.tipwidth > self.winfo_screenwidth():
    			posX = posX-self.winfo_width()-self.tipwidth
    		if posY + self.tipheight > self.winfo_screenheight():
    			posY = posY-self.winfo_height()-self.tipheight
    		#~ print posX,print posY
    		self.geometry('+%d+%d'%(posX,posY))
    		self.deiconify()
    	def efface(self,event):
    		self.withdraw()
    		self.parent.after_cancel(self.action)
     
    if __name__ == '__main__':
    	root = tk.Tk()
    	lab1=tk.Label(root,text='Infobulle 1')
    	lab1.pack()
    	lab2=tk.Label(root,text='Infobulle 2')
    	lab2.pack()
    	i1 = infoBulle(parent=lab1,texte="Infobulle 1")
    	i2= infoBulle(parent=lab2,texte="Infobulle 2")
    	root.mainloop()
    ''' Life is short, use Python '''
    Business En Ligne
    SearchEngineFight

  2. #2
    Nouveau membre du Club
    Inscrit en
    Décembre 2006
    Messages
    30
    Détails du profil
    Informations personnelles :
    Âge : 52

    Informations forums :
    Inscription : Décembre 2006
    Messages : 30
    Points : 27
    Points
    27
    Par défaut
    Bonjour,
    je connais pas FreeBSD mais j'ai testé le script
    et le "temps" est bien trop grand par défaut...
    Ensuite il faut faire un "binding" entre la souris et le texte
    à afficher du type:
    self.can.bind("<B1-motion>",lambda event:self.bougemontexte(event))
    cordialement
    Jluc

  3. #3
    Membre averti
    Homme Profil pro
    Responsable du parc et des réseaux de télécommunication
    Inscrit en
    Mai 2003
    Messages
    290
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Responsable du parc et des réseaux de télécommunication
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2003
    Messages : 290
    Points : 388
    Points
    388
    Par défaut
    Bonjour,
    Je pense que le plus simple est de supprimer la fonction délai.
    (Tkinter génère sans cesse des evenement "LEAVE"). Il n'y a plus de temporisation avant l'affichage de l'infobulle, mais le reste fonctionne correctement (win et Linux):
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    #! /usr/bin/python
     
    import Tkinter as tk
     
    class infoBulle(tk.Toplevel):
        def __init__(self,parent=None,texte=''):
            tk.Toplevel.__init__(self,parent,bd=1,bg='black')
            self.parent=parent
            self.withdraw()
            self.overrideredirect(1)
            self.transient()
            l=tk.Label(self,text=texte,justify='left',bg='yellow')
            l.pack()
            l.update_idletasks()
            self.tipwidth = l.winfo_width()
            self.tipheight = l.winfo_height()
            self.parent.bind('<Enter>',self.affiche)
            self.parent.bind('<Button-1>',self.efface)
            self.parent.bind('<Leave>',self.efface)
            self.parent.bind('<Motion>',self.motion)
     
        def affiche(self,event):
            self.update_idletasks()
            posX=self.parent.winfo_rootx()+event.x+10
            posY=self.parent.winfo_rooty()+event.y+10
            if posX + self.tipwidth > self.winfo_screenwidth():
                posX = posX-self.winfo_width()-self.tipwidth
            if posY + self.tipheight > self.winfo_screenheight():
                posY = posY-self.winfo_height()-self.tipheight
            self.geometry('+%d+%d'%(posX,posY))
            self.deiconify()
            self.update_idletasks()
     
        def motion(self,event):
            posX = self.parent.winfo_rootx()+event.x+10
            posY = self.parent.winfo_rooty()+event.y+10
            if posX + self.tipwidth > self.winfo_screenwidth():
                posX = posX-self.winfo_width()-self.tipwidth
            if posY + self.tipheight > self.winfo_screenheight():
                posY = posY-self.winfo_height()-self.tipheight
            self.geometry('+%d+%d'%(posX,posY))
            self.update_idletasks()
     
        def efface(self,event):
            self.withdraw()
     
    if __name__ == '__main__':
        root = tk.Tk()
        lab1=tk.Label(root,text='infobulle1')
        lab1.pack()
        lab2=tk.Label(root,text='Infobulle 2')
        lab2.pack()
        i1 = infoBulle(parent=lab1,texte="Infobulle 1")
        i2= infoBulle(parent=lab2,texte="Infobulle 2")
        root.mainloop()

Discussions similaires

  1. Réponses: 1
    Dernier message: 08/10/2006, 20h01
  2. Réponses: 3
    Dernier message: 14/09/2006, 08h44
  3. [9i] PLS-00320 avec une fonction qui renvoi un curseur
    Par hoaxpunk dans le forum Oracle
    Réponses: 5
    Dernier message: 09/02/2006, 17h04
  4. [FLASH MX2004] Un bouton qui suit mon curseur...
    Par gregooo dans le forum Flash
    Réponses: 17
    Dernier message: 03/02/2006, 11h27
  5. Procedure stockée qui retourne un curseur
    Par kinaï dans le forum Débuter
    Réponses: 1
    Dernier message: 10/08/2004, 14h42

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo