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 :

deplacer le curseur dans un Tkinter.Text


Sujet :

Tkinter Python

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre Expert
    Profil pro
    Développeur en systèmes embarqués retraité
    Inscrit en
    Mars 2006
    Messages
    952
    Détails du profil
    Informations personnelles :
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur en systèmes embarqués retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2006
    Messages : 952
    Par défaut deplacer le curseur dans un Tkinter.Text
    Bonjour,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    0020 67 30 30 31 00 00 04 00 g001....
    0028 C8 03 67 30 30 32 00 00 ..g002..
    0030 0B 00 C8 03 67 30 30 33 ....g003
    0038 00 00 12 00 C8 03 EA BB ........
    Pour un éditeur de blocs eeprom dans un Tkinter.text, j'aurais besoin de déplacer le curseur sur les caractères éditables, ceux de "67" par exemple mais pas ceux de "g004..." ni de "0020". J'ai donc une table de positions autorisées, comme "1.5" pour le '6' de "67",, mais je n'ai pas la moindre idée pour faire apparaitre un curseur et le déplacer. Je suis preneur de toute piste, merci d'avance.

    A+

    Pfeuh

  2. #2
    Membre chevronné
    Avatar de vincent.mbg
    Homme Profil pro
    Développeur Python
    Inscrit en
    Décembre 2007
    Messages
    327
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Développeur Python

    Informations forums :
    Inscription : Décembre 2007
    Messages : 327
    Par défaut
    Voici un début je te laisse découvrir comment reculer le curseur

    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
     
    from Tkinter import *
     
     
    def controleCursor( event ):
        pos = str( prompt.index( CURRENT ) )
        posHorizontale = int( pos.split('.')[ 1 ] )
        if posHorizontale > 28 :
            """Reculer le curseur"""
     
     
    root = Tk()
    prompt = Text( root )
    prompt.pack()
    prompt.bind( "<Key>" , controleCursor )
    root.mainloop()
    Si le curseur doit reculer à la 28 eme colonne
    Mon guide pour apprendre Tkinter - N'oubliez pas de consulter les FAQ Python ou de visiter mon blog

  3. #3
    Membre Expert
    Profil pro
    Développeur en systèmes embarqués retraité
    Inscrit en
    Mars 2006
    Messages
    952
    Détails du profil
    Informations personnelles :
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur en systèmes embarqués retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2006
    Messages : 952
    Par défaut
    Salut Vincent,

    Merci pour ta réponse, je commençais à désespérer... En fait, je gère le curseur sans problème, ce qui m'embête est juste graphique. Ci dessous un code qui s'exécute comme je le désire, mais le curseur est invisible. J'ai prévu sa gestion dans EDITSECWIN.gotoxy(), mais je sèche toujours.

    <EDIT>
    Je viens de trouver. Je ne suis pas sûr d'avoir pondu la méthode la plus simple, mais elle a le mérite de marcher. Derrière chaque caractère éditable, j'ai posé un tag et j'inverse les couleurs foreground et background. Encore merci.
    </EDIT>

    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
    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
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
     
    from Tkinter import *
    from tkFont import Font
     
    def int2asc(byte, fullcharset = 0):
        if byte < 32:
            return "."
        else:
            if fullcharset:
                return chr(byte)
            else:
                if byte < 128:
                    return chr(byte)
                else:
                    return '.'
     
    def dump(bloc, offset = 0, width = 8, fullcharset = 0):
        bigstr = ""
        for index in range(len(bloc)):
            car = bloc[index]
            byte = ord(car)
            #start of line
            if not (index % width):
                bigstr += "%04X "%(index + offset)
                carbuf = ""
            #any byte
            bigstr += "%02X "%(byte)
            carbuf += int2asc(byte)
            #end of line
            if (index % width) == (width - 1):
                bigstr += carbuf + '\n'
        #line completion*
        if (index % width) != (width -1):
            while (index % width) != (width -1):
                bigstr += "-- "
                index += 1
            bigstr += carbuf + '\n'
        return bigstr
     
    class EDITSECWIN(Tk):
        def __init__(self,sector):
            Tk.__init__(self)
            self.cols = 8
            self.sector = sector
            self.editabletext = dump(sector)
            if(len(self.sector) % self.cols):
                height += 1
            width = 5 + self.cols * 3 + self.cols
            height = len(self.sector) / self.cols
            self.editabledigit = []
            self.editablechar = []
            self.notepad = Text(self,font=Font(family="Terminal",size=16),width=width,height=height)
            self.notepad.grid()
            self.notepad.delete('1.0',END)
            self.notepad.insert(END,self.editabletext)
            self.notepad.update()
            self.notepad.focus()
            self.notepad.bind("<Left>", self.CallLeft)
            self.notepad.bind("<Right>", self.CallRight)
            self.notepad.bind("<Up>", self.CallUp)
            self.notepad.bind("<Down>", self.CallDown)
            self.notepad.bind("<KeyPress>", self.EventCallback)
            for index in range(len(self.sector)):
                line = (index / self.cols) + 1
                col1 = 5 + (index % self.cols) * 3
                col2 = col1 + 1
                col3 = 5 + self.cols * 3 + (index % self.cols)
                pos = "%u.%u"%(line,col1)
                self.editabledigit.append("%u.%u"%(line,col1))
                self.editabledigit.append("%u.%u"%(line,col2))
                self.editablechar.append("%u.%u"%(line,col3))            
                self.notepad.tag_add("%u.%u"%(line,col1), "%u.%u"%(line,col1))
                self.notepad.tag_add("%u.%u"%(line,col2), "%u.%u"%(line,col2))
     
            self.editcursor = 0
            self.gotoxy(1)
     
        def gotoxy(self,active = 1):
            locator = self.editabledigit[self.editcursor]
            self.title(locator)
            if active:
                self.notepad.tag_config(locator, foreground = 'WHITE')
                self.notepad.tag_config(locator, background = 'BLACK')
            else:
                self.notepad.tag_config(locator, foreground = 'BLACK')
                self.notepad.tag_config(locator, background = 'WHITE')
     
        def CallLeft(self,event):
            self.gotoxy(0)
            self.editcursor -= 1
            if self.editcursor == -1:
                self.editcursor = len(self.editabledigit) - 1
            self.gotoxy()
            return "break"
     
        def CallRight(self,event):
            self.gotoxy(0)
            self.editcursor += 1
            if self.editcursor >= len(self.editabledigit):
                self.editcursor = 0
            self.gotoxy()
            return "break"
     
        def CallUp(self,event):
            self.gotoxy(0)
            self.editcursor -= self.cols * 2
            if self.editcursor < 0:
                self.editcursor += len(self.editabledigit)
            self.gotoxy()
            return "break"
     
        def CallDown(self,event):
            self.gotoxy(0)
            self.editcursor += self.cols * 2
            if self.editcursor >= len(self.editabledigit):
                self.editcursor -= len(self.editabledigit)
            self.gotoxy()
            return "break"
     
        def EventCallback(self,event):
            car = event.char.upper()
            if not car in ("0123456789abcdefABCDEF"):
                pass
            else:
                self.notepad.delete(self.editabledigit[self.editcursor])
                self.notepad.insert(self.editabledigit[self.editcursor],car)
                byte_str = "%c%c"%(self.notepad.get(self.editabledigit[self.editcursor / 2 * 2]),self.notepad.get(self.editabledigit[self.editcursor / 2 * 2 + 1]))
                car = int2asc(int(byte_str,16))
                self.notepad.delete(self.editablechar[self.editcursor >> 1])
                self.notepad.insert(self.editablechar[self.editcursor >> 1],car)
                self.CallRight(0)
            return "break"
     
    if __name__ == "__main__":
     
        root = EDITSECWIN("Ceci est un bloc de 32 octets...")
        root.mainloop()
    A+

    Pfeuh

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Débutant:Curseur dans zone de Texte
    Par DuDe92 dans le forum IHM
    Réponses: 7
    Dernier message: 05/01/2007, 17h04
  2. [VB6] position du curseur dans une zone texte et insertion caractere
    Par tim69000 dans le forum VB 6 et antérieur
    Réponses: 3
    Dernier message: 05/05/2006, 09h52
  3. Deplacer le curseur dans une cellule de DBGrid
    Par Sydaze dans le forum Composants VCL
    Réponses: 6
    Dernier message: 07/11/2005, 16h19
  4. Probleme d'affichage du curseur dans un chp texte avec firef
    Par dadovb dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 20/10/2005, 12h31
  5. Deplacer un curseur dans un RichEdit sous visual c
    Par tweek dans le forum Windows
    Réponses: 7
    Dernier message: 14/01/2004, 00h29

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