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 :

Toplevel : Information sur l'état du parent (réduction, redimensionnement)


Sujet :

Tkinter Python

  1. #1
    Expert confirmé Avatar de PauseKawa
    Homme Profil pro
    Technicien Help Desk, maintenance, réseau, système et +
    Inscrit en
    Juin 2006
    Messages
    2 725
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Technicien Help Desk, maintenance, réseau, système et +
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2006
    Messages : 2 725
    Points : 4 005
    Points
    4 005
    Par défaut Toplevel : Information sur l'état du parent (réduction, redimensionnement)
    Bonjour,

    Quel est d'après vous la meilleure façon de suivre l'état (réduction, redimensionnement) du parent dans le cadre d'un toplevel ?
    Le but de la question c'est de repositionner celui ci.

    Pour comprendre la question voici mon début de code :

    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
    138
    139
    140
    141
    142
    143
    144
    try: from tkinter import *
    except: from Tkinter import *
     
    # Class TkComboBox
    # ComboBox en pur Tkinter
    #
    # Options:
    # width, height, border, background (bg) , foreground (fg), font, relief, cursor,
    # exportselection, selectbackgroun, selectforeground
    #
    # Methodes:
    # activate(int index) => int
    # curselection() => int
    # delete(objet=["ALL" ou int]
    # start=int
    # end=["END" ou int]
    # focus_set()
    # focus()
    # get()
    # pack(padx=int, pady=int, fill(X, Y, BOTH), expand=bool, side=LEFT, RIGHT, TOP, BOTTOM, CENTER)
    # grid(row=int, column=int, columnspan=int, rowspan=int, sticky=NSEW, padx=int, pady=int)
    # place(relheight=int, relwidth=int, relx=int, rely=int, width=int, height=int, anchor=NSEW, x=int, y=int)
    #
    class TkComboBox(Toplevel):
        listeobjets = []
     
        def activate(self, index):
            self.selection.activate(index)
     
        def curselection(self):
            return map(int, self.selection.curselection())[0]
     
        def delete(self, objet=None, start=None, end=None):
            if objet=='ALL':
                self.selection.delete(0, END)
            elif start == None and end == None:
                self.selection.delete(objet)
            else:
                self.selection.delete(start, end)
     
        def get_focus(self):
            self.zoneselection.get_focus()
     
        def focus(self):
            self.zoneselection.get_focus()
     
        def get(self):
            return self.zoneselection.get()
     
        def pack(self, padx=None, pady=None, fill=None, expand=None, side=None):
            self.conteneur.pack(padx=padx, pady=pady, fill=fill, expand=expand, side=side)
            self.affiche()
     
        def grid(self, row=None, column=None, columnspan=None, rowspan=None, sticky=None, padx=None, pady=None):
            self.conteneur.grid(row=row, column=column, columnspan=columnspan, rowspan=rowspan, sticky=sticky, padx=padx, pady=pady)
            self.affiche()
     
        def place(self, relheight=None, relwidth=None, relx=None, rely=None, width=None, height=None, anchor=None, x=None, y=None):
            self.conteneur.place(relheight=relheight, relwidth=relwidth, relx=relx, rely=rely, width=width, height=height, anchor=anchor, x=x, y=y)
            self.affiche()
     
        def affiche(self):
            self.update_idletasks()
            self.geometry('+%d+%d'%(self.conteneur.winfo_rootx(),self.conteneur.winfo_rooty()))
            self.selection.bind("<ButtonPress-1>", self.selectionner)
            self.zoneselection.bind("<ButtonPress-1>", self.widgetstate)
            self.valeur_widget_state = True
            self.widgetstate()
            self.deiconify()
            del(self.conteneur)
     
        def size(self):
            return self.selection.size()
     
        def insert(self, start, objet):
            self.listeobjets.append(objet)
            self.selection.insert(start, objet)
            self.selection.select_set(0)
            self.zoneselection.delete(0, END)
            self.zoneselection.insert(0, self.selection.get(self.selection.curselection()))
     
        def selectionner(self, event):
            def index(event):
                try:
                    self.zoneselection.delete(0, END)
                    self.zoneselection.insert(0, self.selection.get(self.selection.curselection()))
                except:
                    pass
                self.widgetstate()
            self.selection.bind("<ButtonRelease-1>", index)
     
        def widgetstate(self, event=None):
            # True : Visible
            # False : Cache la listbox
            if self.valeur_widget_state == True:
                self.valeur_widget_state = False
                self.listescroll.pack_forget()
                self.selection.pack_forget()
            elif self.valeur_widget_state == False:
                self.valeur_widget_state = True
                self.listescroll.pack(side=RIGHT, fill=Y)
                self.selection.pack(fill=X)
     
        def __init__(self, parent=None, width=None, border=1, background=None, foreground=None, fg=None, bg=None, font=None, relief=None, cursor=None, exportselection=None, selectbackgroun=None, selectforeground=None, height=None):
            Toplevel.__init__(self, parent, bd=0)
            self.parent = parent
            self.conteneur = Label(parent, bg=bg, width=width, height=height)
            self.withdraw()
            self.overrideredirect(1)
            self.transient()
            self.zoneselection = Entry(self, width=None, border=border, background=background, foreground=foreground, fg=fg, bg=bg, font=font, relief=relief, cursor=cursor, exportselection=exportselection, selectbackgroun=selectbackgroun, selectforeground=selectforeground, height=height)
            self.zoneselection.pack(fill=X)
            self.listescroll = Scrollbar(self)
            self.listescroll.pack(side=RIGHT, fill=Y)
            self.selection = Listbox(self, yscrollcommand=self.listescroll.set, width=None, border=border, background=background, foreground=foreground, fg=fg, bg=bg, font=font, relief=relief, cursor=cursor, exportselection=exportselection, selectbackgroun=selectbackgroun, selectforeground=selectforeground, height=height)
            self.selection.pack(fill=X)
            self.listescroll.config(command=self.selection.yview)
     
    class test(Tk):
        def __init__(self):
            Tk.__init__(self)
            monexplication = """        Tk.__init__(self)
            self.geometry(str(self.winfo_screenwidth())+'x'
                +str(self.winfo_screenheight())+'+0+0')
            self.explication = Text(self, bg='white')
            self.explication.insert(END, monexplication)
            self.explication.pack(side=TOP)
            self.listeMini = MonComboBox(self, width=200, bg='black', fg='white')
            self.listeMini.pack(side=TOP, pady=20)
            for index in range(0,100):
                self.listeMini.insert(index, index)
            Button(self, text='QUIT', command=self.quit).pack(side=TOP, pady=20)"""
            self.explication = Text(self, bg='white')
            self.explication.insert(END, monexplication)
            self.explication.pack(side=TOP)
            self.listeMini = TkComboBox(self, width=10, bg='black', fg='white')
            self.listeMini.pack(side=TOP, pady=20)
            for index in range(0,100):
                self.listeMini.insert(index, index)
            Button(self, text='QUIT', command=self.quit).pack(side=TOP, pady=20)
     
    if __name__ == '__main__':
        app = test()
        app.mainloop()
    Merci d'avance

    @+

  2. #2
    Expert confirmé Avatar de PauseKawa
    Homme Profil pro
    Technicien Help Desk, maintenance, réseau, système et +
    Inscrit en
    Juin 2006
    Messages
    2 725
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Technicien Help Desk, maintenance, réseau, système et +
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2006
    Messages : 2 725
    Points : 4 005
    Points
    4 005
    Par défaut
    J'ai parfois tendance à ne pas voir ce que devant...

    Solution :
    self.parent.bind("<Configure>", self.reposition) pour les déplacements/redimensionnements et protocol pour la réduction.

  3. #3
    Expert confirmé Avatar de PauseKawa
    Homme Profil pro
    Technicien Help Desk, maintenance, réseau, système et +
    Inscrit en
    Juin 2006
    Messages
    2 725
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Technicien Help Desk, maintenance, réseau, système et +
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2006
    Messages : 2 725
    Points : 4 005
    Points
    4 005
    Par défaut
    Bonjour,

    Cela avance mais il me reste un souci pour le state: Je récupère bien l'iconic mais comment faire pour les autres états ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
        self.parent.bind("<Configure>", self.reposition)
        self.parent.bind("<Unmap>", self.reposition)
    ....
        def reposition(self, event):
            if self.parent.state() == 'iconic':
                self.withdraw()
            else:
                self.withdraw()
                self.geometry('+%d+%d'%(self.conteneur.winfo_rootx(),self.conteneur.winfo_rooty()))
                self.deiconify()
    Comment récupérer la restauration de la fenêtre ? Si quelqu'un a une idée...

    Merci d'avance

  4. #4
    Expert confirmé Avatar de PauseKawa
    Homme Profil pro
    Technicien Help Desk, maintenance, réseau, système et +
    Inscrit en
    Juin 2006
    Messages
    2 725
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Technicien Help Desk, maintenance, réseau, système et +
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2006
    Messages : 2 725
    Points : 4 005
    Points
    4 005
    Par défaut
    Rectification, cela fonctionne sous Vista mais pas sous Linux.
    Quelqu'un a une idée ?

    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
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    try: from tkinter import *
    except: from Tkinter import *
     
    # Class TkComboBox
    # ComboBox en pur Tkinter
    #
    # Options:
    # width, height, border, background (bg) , foreground (fg), font, relief, cursor,
    # exportselection, selectbackgroun, selectforeground
    #
    # Methodes:
    # activate(int index) => int
    # curselection() => int
    # delete(objet=["ALL" ou int]
    # start=int
    # end=["END" ou int]
    # focus_set()
    # focus()
    # get()
    # pack(padx=int, pady=int, fill(X, Y, BOTH), expand=bool, side=LEFT, RIGHT, TOP, BOTTOM, CENTER)
    # grid(row=int, column=int, columnspan=int, rowspan=int, sticky=NSEW, padx=int, pady=int)
    # place(relheight=int, relwidth=int, relx=int, rely=int, width=int, height=int, anchor=NSEW, x=int, y=int)
    #
    class TkComboBox(Toplevel):
        listeobjets = []
     
        def activate(self, index):
            self.selection.activate(index)
     
        def curselection(self):
            return map(int, self.selection.curselection())[0]
     
        def delete(self, objet=None, start=None, end=None):
            if objet=='ALL':
                self.selection.delete(0, END)
            elif start == None and end == None:
                self.selection.delete(objet)
            else:
                self.selection.delete(start, end)
     
        def get_focus(self):
            self.zoneselection.get_focus()
     
        def focus(self):
            self.zoneselection.get_focus()
     
        def get(self):
            return self.zoneselection.get()
     
        def pack(self, padx=None, pady=None, fill=None, expand=None, side=None):
            self.conteneur.pack(padx=padx, pady=pady, fill=fill, expand=expand, side=side)
            self.affiche()
     
        def grid(self, row=None, column=None, columnspan=None, rowspan=None, sticky=None, padx=None, pady=None):
            self.conteneur.grid(row=row, column=column, columnspan=columnspan, rowspan=rowspan, sticky=sticky, padx=padx, pady=pady)
            self.affiche()
     
        def place(self, relheight=None, relwidth=None, relx=None, rely=None, width=None, height=None, anchor=None, x=None, y=None):
            self.conteneur.place(relheight=relheight, relwidth=relwidth, relx=relx, rely=rely, width=width, height=height, anchor=anchor, x=x, y=y)
            self.affiche()
     
        def affiche(self):
            self.update_idletasks()
            self.geometry('+%d+%d'%(self.conteneur.winfo_rootx(),self.conteneur.winfo_rooty()))
            self.selection.bind("<ButtonPress-1>", self.selectionner)
            self.zoneselection.bind("<ButtonPress-1>", self.widgetstate)
            self.valeur_widget_state = True
            self.widgetstate()
            self.deiconify()
            self.parent.bind("<Configure>", self.reposition)
            self.parent.bind("<Unmap>", self.reposition)
     
        def size(self):
            return self.selection.size()
     
        def insert(self, start, objet):
            self.listeobjets.append(objet)
            self.selection.insert(start, objet)
            self.selection.select_set(0)
            self.zoneselection.delete(0, END)
            self.zoneselection.insert(0, self.selection.get(self.selection.curselection()))
     
        def selectionner(self, event):
            def index(event):
                try:
                    self.zoneselection.delete(0, END)
                    self.zoneselection.insert(0, self.selection.get(self.selection.curselection()))
                except:
                    pass
                self.widgetstate()
            self.selection.bind("<ButtonRelease-1>", index)
     
        def widgetstate(self, event=None):
            # True : Visible
            # False : Cache la listbox
            if self.valeur_widget_state == True:
                self.valeur_widget_state = False
                self.listescroll.pack_forget()
                self.selection.pack_forget()
            elif self.valeur_widget_state == False:
                self.valeur_widget_state = True
                self.listescroll.pack(side=RIGHT, fill=Y)
                self.selection.pack(fill=X)
     
        def __init__(self, parent=None, width=None, border=1, background=None, foreground=None, fg=None, bg=None, font=None, relief=None, cursor=None, exportselection=None, selectbackgroun=None, selectforeground=None, height=None):
            Toplevel.__init__(self, parent, bd=0)
            self.parent = parent
            self.conteneur = Label(parent, border=border, fg=fg, bg=bg, font=font, relief=relief, cursor=cursor, exportselection=exportselection, selectbackgroun=selectbackgroun, selectforeground=selectforeground, height=height, width=width, background=background, foreground=foreground)
            self.withdraw()
            self.overrideredirect(1)
            self.transient()
            self.zoneselection = Entry(self, width=None, border=border, background=background, foreground=foreground, fg=fg, bg=bg, font=font, relief=relief, cursor=cursor, exportselection=exportselection, selectbackgroun=selectbackgroun, selectforeground=selectforeground, height=height)
            self.zoneselection.pack(fill=X)
            self.listescroll = Scrollbar(self)
            self.listescroll.pack(side=RIGHT, fill=Y)
            self.selection = Listbox(self, yscrollcommand=self.listescroll.set, width=None, border=border, background=background, foreground=foreground, fg=fg, bg=bg, font=font, relief=relief, cursor=cursor, exportselection=exportselection, selectbackgroun=selectbackgroun, selectforeground=selectforeground, height=height)
            self.selection.pack(fill=X)
            self.listescroll.config(command=self.selection.yview)
     
        def reposition(self, event):
            if self.parent.state() == 'iconic':
                self.withdraw()
            else:
                self.withdraw()
                self.geometry('+%d+%d'%(self.conteneur.winfo_rootx(),self.conteneur.winfo_rooty()))
                self.deiconify()
     
    class test(Tk):
        def __init__(self):
            Tk.__init__(self)
            monexplication = """        Tk.__init__(self)
            self.geometry(str(self.winfo_screenwidth())+'x'
                +str(self.winfo_screenheight())+'+0+0')
            self.explication = Text(self, bg='white')
            self.explication.insert(END, monexplication)
            self.explication.pack(side=TOP)
            self.listeMini = MonComboBox(self, width=200, bg='black', fg='white')
            self.listeMini.pack(side=TOP, pady=20)
            for index in range(0,100):
                self.listeMini.insert(index, index)
            Button(self, text='QUIT', command=self.quit).pack(side=TOP, pady=20)"""
            self.explication = Text(self, bg='white')
            self.explication.insert(END, monexplication)
            self.explication.pack(side=TOP)
            self.listeMini = TkComboBox(self, width=10, bg='black', fg='white')
            self.listeMini.pack(side=TOP, pady=20)
            for index in range(0,100):
                self.listeMini.insert(index, index)
            Button(self, text='QUIT', command=self.quit).pack(side=TOP, pady=20)
     
    if __name__ == '__main__':
        app = test()
        app.mainloop()

  5. #5
    Membre confirmé
    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 : 37
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Développeur Python

    Informations forums :
    Inscription : Décembre 2007
    Messages : 327
    Points : 618
    Points
    618
    Par défaut
    Bonjour,

    Quelle doit être l'interaction entre le Toplevel est la fenêtre Principale ?

    Edit : pourquoi ne pas dériver ta combobox d'une Frame ?

  6. #6
    Expert confirmé Avatar de PauseKawa
    Homme Profil pro
    Technicien Help Desk, maintenance, réseau, système et +
    Inscrit en
    Juin 2006
    Messages
    2 725
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Technicien Help Desk, maintenance, réseau, système et +
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2006
    Messages : 2 725
    Points : 4 005
    Points
    4 005
    Par défaut
    Bonjour,

    Le Toplevel dois se positionner systématiquement au niveau de self.conteneur.
    C'est bon pour le déplacement du parent (self.parent.bind("<Configure>", self.reposition)), pour la réduction (self.parent.bind("<Unmap>", self.reposition)) mais lors de la restauration du parent cela fonctionne sous Windows mais pas sous Linux (voir def reposition) car sous Linux <Unmap> n'est pas pris en compte à la restauration et le Toplevel reste withdraw().

    Pour ce qui est d'une Frame le fait de faire apparaitre la liste (def widgetstate) modifie la géométrie du parent (tout ce qui est dessous au niveau gestionnaire de géométrie). De plus le Toplevel permet d'afficher la liste 'au dessus' des autres widgets.

  7. #7
    Expert confirmé Avatar de PauseKawa
    Homme Profil pro
    Technicien Help Desk, maintenance, réseau, système et +
    Inscrit en
    Juin 2006
    Messages
    2 725
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Technicien Help Desk, maintenance, réseau, système et +
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2006
    Messages : 2 725
    Points : 4 005
    Points
    4 005
    Par défaut
    J'ai du mal comprendre pour ce qui est de la Frame. Tu parle de class TkComboBox(Frame) ?
    Si oui comment vois tu la chose ?

  8. #8
    Membre confirmé
    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 : 37
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Développeur Python

    Informations forums :
    Inscription : Décembre 2007
    Messages : 327
    Points : 618
    Points
    618
    Par défaut
    l'esthétique de ton widget rend vraiment bien, Bravo !

    Mais je pense que tu pourrais envisager une solution plus simple.

    Se serait de partir du label self.conteneur.

    lors d'un clique sur ce Label, ton Toplevel avec la scrolled_list apparait.
    Le master de ce label(root) ce met en attente, (C'est assez classique) on ne peut ni le déplacer ni l'iconiffier. Lorsque tu clique sur un élément de ta liste, cette élément s'inscrit dans le Label et le Toplevel disparait et root n'est plus en attente.

    Il y a aussi un widget Menu dans Tkinter c'est un peu comme un Toplevel sans cadre je pense qu'il serait plus adapté qu'un Toplevel mais je ne connais pas ses capacités en tant que conteneur voici un exemple avec Menu

    J'espère que ça pourra te faire avancé, car je ne peux pas plus d'aider pour le moment.

  9. #9
    Membre confirmé Avatar de calogerogigante
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    602
    Détails du profil
    Informations personnelles :
    Âge : 53
    Localisation : Belgique

    Informations forums :
    Inscription : Avril 2003
    Messages : 602
    Points : 497
    Points
    497
    Par défaut
    C'est vrai qu'il est bien ce TkComboBox en "pur Tkinter"...

    Pourrons-nous en profiter librement quand il sera fini, pour nos projets ?

  10. #10
    Expert confirmé Avatar de PauseKawa
    Homme Profil pro
    Technicien Help Desk, maintenance, réseau, système et +
    Inscrit en
    Juin 2006
    Messages
    2 725
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Technicien Help Desk, maintenance, réseau, système et +
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2006
    Messages : 2 725
    Points : 4 005
    Points
    4 005
    Par défaut
    Bonjour,

    Suite aux idées de vincent.mbg voici ce que cela donne (pas eu le temps de tester, c'est tout chaud de ce matin ).

    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
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    try: from tkinter import *
    except: from Tkinter import *
     
    # Class TkComboBox
    # ComboBox en pur Tkinter
    #
    # Options:
    # width, height, border, background (bg) , foreground (fg), font, relief, cursor,
    # exportselection, selectbackgroun, selectforeground
    #
    # Methodes:
    # activate(int index) => int
    # curselection() => int
    # delete(objet=["ALL" ou int]
    # start=int
    # end=["END" ou int]
    # insert(index, valeur)
    # focus_set()
    # focus()
    # get()
    # pack(padx=int, pady=int, fill(X, Y, BOTH), expand=bool, side=LEFT, RIGHT, TOP, BOTTOM, CENTER)
    # grid(row=int, column=int, columnspan=int, rowspan=int, sticky=NSEW, padx=int, pady=int)
    # place(relheight=int, relwidth=int, relx=int, rely=int, width=int, height=int, anchor=NSEW, x=int, y=int)
    # config/configure(Option=Value)
    #
    class TkComboBox(Toplevel):
        listeobjets = []
     
        def configure(self, **kw):
            for cle in kw:
                option=cle
                valeur=kw[cle]
                self.zoneselection[option]=valeur
                self.cache[option]=valeur
                self.selection[option]=valeur
     
        config=configure
     
        def activate(self, index):
            self.selection.activate(index)
     
        def curselection(self):
            return map(int, self.selection.curselection())[0]
     
        def delete(self, objet=None, start=None, end=None):
            if objet=='ALL':
                self.selection.delete(0, END)
            elif start == None and end == None:
                self.selection.delete(objet)
            else:
                self.selection.delete(start, end)
     
        def get_focus(self):
            self.zoneselection.get_focus()
     
        def focus(self):
            self.zoneselection.get_focus()
     
        def get(self):
            return self.zoneselection.get()
     
        def pack(self, padx=None, pady=None, fill=None, expand=None, side=None):
            self.zoneselection.pack(padx=padx, pady=pady, fill=fill, expand=expand, side=side)
     
        def grid(self, row=None, column=None, columnspan=None, rowspan=None, sticky=None, padx=None, pady=None):
            self.zoneselection.grid(row=row, column=column, columnspan=columnspan, rowspan=rowspan, sticky=sticky, padx=padx, pady=pady)
     
        def place(self, relheight=None, relwidth=None, relx=None, rely=None, width=None, height=None, anchor=None, x=None, y=None):
            self.zoneselection.place(relheight=relheight, relwidth=relwidth, relx=relx, rely=rely, width=width, height=height, anchor=anchor, x=x, y=y)
     
        def size(self):
            return self.selection.size()
     
        def insert(self, start, objet):
            self.listeobjets.append(objet)
            self.selection.insert(start, objet)
            self.selection.select_set(0)
            self.zoneselection.delete(0, END)
            self.zoneselection.insert(0, self.selection.get(self.selection.curselection()))
            self.cache.delete(0, END)
            self.cache.insert(0, self.selection.get(self.selection.curselection()))
     
        def selectionner(self, event):
            def index(event):
                try:
                    self.zoneselection.delete(0, END)
                    self.zoneselection.insert(0, self.selection.get(self.selection.curselection()))
                    self.cache.delete(0, END)
                    self.cache.insert(0, self.selection.get(self.selection.curselection()))
                except:
                    pass
                self.widgetstate()
            self.selection.bind("<ButtonRelease-1>", index)
     
        def widgetstate(self, event=None):
            # True : Visible
            # False : Cache la listbox
            self.geometry('+%d+%d'%(self.zoneselection.winfo_rootx(),self.zoneselection.winfo_rooty()))
            if self.valeur_widget_state == True:
                self.valeur_widget_state = False
                self.withdraw()
            elif self.valeur_widget_state == False:
                self.valeur_widget_state = True
                self.deiconify()
     
        def __init__(self, parent=None, width=None, border=1, background=None, foreground=None, fg=None, bg=None, font=None, relief=None, cursor=None, exportselection=None, selectbackgroun=None, selectforeground=None, height=None):
            Toplevel.__init__(self, parent, bd=0)
            self.withdraw()
            self.parent = parent
            self.zoneselection = Entry(parent, border=border, fg=fg, bg=bg, font=font, relief=relief, cursor=cursor, exportselection=exportselection, selectbackgroun=selectbackgroun, selectforeground=selectforeground, height=height, width=width, background=background, foreground=foreground)
            self.overrideredirect(1)
            self.transient()
            self.listescroll = Scrollbar(self)
            self.listescroll.pack(side=RIGHT, fill=Y)
            self.cache = Entry(self, border=border, fg=fg, bg=bg, font=font, relief=relief, cursor=cursor, exportselection=exportselection, selectbackgroun=selectbackgroun, selectforeground=selectforeground, height=height, width=width, background=background, foreground=foreground)
            self.cache.pack(fill=X)
            self.selection = Listbox(self, yscrollcommand=self.listescroll.set, width=None, border=border, background=background, foreground=foreground, fg=fg, bg=bg, font=font, relief=relief, cursor=cursor, exportselection=exportselection, selectbackgroun=selectbackgroun, selectforeground=selectforeground, height=height)
            self.selection.pack(fill=X)
            self.listescroll.config(command=self.selection.yview)
            self.update_idletasks()
            self.selection.bind("<ButtonPress-1>", self.selectionner)
            self.cache.bind("<ButtonPress-1>", self.widgetstate)
            self.zoneselection.bind("<ButtonPress-1>", self.widgetstate)
            self.valeur_widget_state = True
            self.widgetstate()
            self.parent.bind("<Unmap>", self.reposition)
            self.parent.bind("<Configure>", self.reposition)
     
        def reposition(self, event):
            self.withdraw()
     
    class test(Tk):
        def __init__(self):
            Tk.__init__(self)
            monexplication = """Sample: Tk.__init__(self)
            self.geometry(str(self.winfo_screenwidth())+'x'
                +str(self.winfo_screenheight())+'+0+0')
            self.explication = Text(self, bg='white')
            self.explication.insert(END, monexplication)
            self.explication.pack(side=TOP)
            self.listeMini = TkComboBox(self, width=10, bg='black', fg='white')
            self.listeMini.pack(side=TOP, pady=20)
            self.listeMini.config(bg='white', fg='black')
            for index in range(0,100):
                self.listeMini.insert(index, index)
            Button(self, text='QUIT', command=self.quit).pack(side=TOP, pady=20)"""
            self.explication = Text(self, bg='white')
            self.explication.insert(END, monexplication)
            self.explication.pack(side=TOP)
            self.listeMini = TkComboBox(self, width=10, bg='black', fg='white')
            self.listeMini.pack(side=TOP, pady=20)
            self.listeMini.config(bg='white', fg='black')
            for index in range(0,100):
                self.listeMini.insert(index, index)
            Button(self, text='QUIT', command=self.quit).pack(side=TOP, pady=20)
     
    if __name__ == '__main__':
        app = test()
        app.mainloop()
    Vous en pensez quoi ?

    Petit edit pour config/configure

  11. #11
    Expert confirmé Avatar de PauseKawa
    Homme Profil pro
    Technicien Help Desk, maintenance, réseau, système et +
    Inscrit en
    Juin 2006
    Messages
    2 725
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Technicien Help Desk, maintenance, réseau, système et +
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2006
    Messages : 2 725
    Points : 4 005
    Points
    4 005
    Par défaut
    Bonjour,

    Citation Envoyé par calogerogigante Voir le message
    Pourrons-nous en profiter librement quand il sera fini, pour nos projets ?
    Bien sur.
    Le but est d'apporter des ressources à tkinter afin d'éviter les imports de bibliothèques. Donc si c'est utilisé c'est bien
    De plus un béta testeur (et tout commentaires) est le bienvenu.

    Citation Envoyé par vincent.mbg Voir le message
    Mais je pense que tu pourrais envisager une solution plus simple.

    Se serait de partir du label self.conteneur.

    lors d'un clique sur ce Label, ton Toplevel avec la scrolled_list apparait.
    Le master de ce label(root) ce met en attente, (C'est assez classique) on ne peut ni le déplacer ni l'iconiffier. Lorsque tu clique sur un élément de ta liste, cette élément s'inscrit dans le Label et le Toplevel disparait et root n'est plus en attente.

    Il y a aussi un widget Menu dans Tkinter c'est un peu comme un Toplevel sans cadre je pense qu'il serait plus adapté qu'un Toplevel mais je ne connais pas ses capacités en tant que conteneur voici un exemple avec Menu

    J'espère que ça pourra te faire avancé, car je ne peux pas plus d'aider pour le moment.
    Le lien n'est plus bon vers ton projet vincent.mbg, pourrais tu donner un exemple ?
    Pour ce qui est du frame c'étais mon idée au départ (aprés tout c'est la conteneur par excellence). Je suis passé au toplevel pour l'histoire de la géométrie du parent. Si tu as une idée a ce niveau je prend.

    Pensez vous que cela soit assez utile pour créer un sujet ?

  12. #12
    Expert confirmé Avatar de PauseKawa
    Homme Profil pro
    Technicien Help Desk, maintenance, réseau, système et +
    Inscrit en
    Juin 2006
    Messages
    2 725
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Technicien Help Desk, maintenance, réseau, système et +
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2006
    Messages : 2 725
    Points : 4 005
    Points
    4 005
    Par défaut
    Citation Envoyé par PauseKawa Voir le message
    Pensez vous que cela soit assez utile pour créer un sujet ?
    Fais...

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

Discussions similaires

  1. Réponses: 0
    Dernier message: 19/03/2011, 19h25
  2. WMI - information sur l'état d'un processus ?
    Par Timothy dans le forum VBScript
    Réponses: 1
    Dernier message: 07/08/2007, 11h14
  3. Réponses: 12
    Dernier message: 12/12/2004, 14h25
  4. Informations sur les procédures stockées
    Par jfphan dans le forum MS SQL Server
    Réponses: 4
    Dernier message: 13/01/2004, 14h30
  5. Réponses: 6
    Dernier message: 28/09/2003, 17h49

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