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

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre Expert 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
    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
    Membre Expert 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
    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
    Membre Expert 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
    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
    Membre Expert 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
    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 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
    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 ?
    Mon guide pour apprendre Tkinter - N'oubliez pas de consulter les FAQ Python ou de visiter mon blog

  6. #6
    Membre Expert 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
    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.

+ 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