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 :

Switch Fenêtre Tkinter


Sujet :

Tkinter Python

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2020
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mars 2020
    Messages : 12
    Points : 9
    Points
    9
    Par défaut Switch Fenêtre Tkinter
    Bonsoir,

    Alors voilà je suis sur un projet Python qui a pour but de gérer des .txt, je ne suis pas du tout avancé en python je m'aide énormément avec internet.

    J'ai fais deux fenêtre tkinter, une fenêtre principale avec tous les outils, à chaque outils une sous fenêtre lui est attribué.

    Interface principale:

    Nom : Screenshot_2.png
Affichages : 1207
Taille : 5,2 Ko

    Là j'aimerai faire en sorte que lorsqu'on clique sur "Anti-Duplicate" ça me switch sur cette fenêtre là:

    Nom : Screenshot_3.png
Affichages : 910
Taille : 4,9 Ko

    Et malheureusement j'ai beau chercher sur internet, je vois beaucoup de switch entre label mais pas avec des fenêtres.
    J'aimerai vraiment que ça switch de fenêtre, et non que ouvre juste l'autre par dessus.

    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
    #coding:utf-8
     
    from tkinter import *
    import os
    import tkinter as tk
    import webbrowser 
    from tkinter import messagebox
    import subprocess
    import time
     
    #Customisation Bouton:
     
    class HoverButton(tk.Button):
        def __init__(self, master, **kw):
            tk.Button.__init__(self,master=master,**kw)
            self.defaultBackground = self["background"]
            self.bind("<Enter>", self.on_enter)
            self.bind("<Leave>", self.on_leave)
     
        def on_enter(self, e):
            self['background'] = self['activebackground']
     
        def on_leave(self, e):
            self['background'] = self.defaultBackground
     
    #---------------------------------------------------------------------
     
    #Fenêtre Anti-Duplicate:
     
    def Anti_Duplicate():
     
        global Anti_Duplicate
        A_Duplicate = Tk()
        A_Duplicate.resizable(width=False, height=False)
        screenn_x = int(A_Duplicate.winfo_screenwidth())
        A_Duplicate.config(background='#1c2028')
        screenn_y = int(A_Duplicate.winfo_screenheight()) 
        A_Duplicate.title("Anti-Duplicate v0.0.1")
        windowss_x = 570
        windowss_y = 340
     
        possX = (screenn_x // 2) - (windowss_x // 2)
        possY = (screenn_y // 2) - (windowss_y // 2)
     
        geoo = "{}x{}+{}+{}".format(windowss_x, windowss_y, possX, possY)
        A_Duplicate.geometry(geoo)
     
        mainframe = Frame(A_Duplicate, bg='#1c2028')
        mainframe.pack(side= TOP, ipadx= 5, ipady= 5)
     
        bouton_1 = HoverButton(A_Duplicate, font=("Arial", 10), text="Back", background='#1c2028', fg='white',  borderwidth=2, activebackground= '#202124', activeforeground='#1195cf', relief='ridge', command= main_menu)
        bouton_1.place(x=520, y=300)
     
        bouton_1 = Button(mainframe, font=("Arial", 15), text="Anti-Duplicate", background='#202124', fg='#1195cf',  borderwidth=2, activebackground= '#202124', activeforeground='#1195cf', relief='sunken')
        bouton_1.pack(padx= 5, pady=10, ipadx= 30)
     
     
    #Fenêtre principale:
     
    def main_menu():
        global main_menu
     
        main_screen = Tk()
        main_screen.resizable(width=False, height=False)
        screenn_x = int(main_screen.winfo_screenwidth())
        main_screen.config(background='#1c2028')
        screenn_y = int(main_screen.winfo_screenheight()) 
        main_screen.title("ComboKit v0.0.1")
        windowss_x = 570
        windowss_y = 340
     
        possX = (screenn_x // 2) - (windowss_x // 2)
        possY = (screenn_y // 2) - (windowss_y // 2)
     
        geoo = "{}x{}+{}+{}".format(windowss_x, windowss_y, possX, possY)
        main_screen.geometry(geoo)
     
        mainframe = Frame(main_screen, bg='#1c2028')
        mainframe.pack(side= TOP, ipadx= 5, ipady= 5)
     
        bouton_1 = HoverButton(mainframe, font=("Arial", 15), text="Fusion", background='#1c2028', fg='white',  borderwidth=2, activebackground= '#202124', activeforeground='#1195cf', relief='ridge')
        bouton_1.pack(side= LEFT, padx= 5, pady=5, ipadx= 30)
     
        bouton_2 = HoverButton(mainframe, font=("Arial", 15), text="Anti-Duplicate", background='#1c2028', fg='white',  borderwidth=2, activebackground= '#202124', activeforeground='#1195cf', relief='ridge')
        bouton_2.pack(side= LEFT, padx= 5, pady=5, ipadx= 30)
     
        bouton_3 = HoverButton(mainframe, font=("Arial", 15), text="Split*", background='#1c2028', fg='white',  borderwidth=2, activebackground= '#202124', activeforeground='#1195cf', relief='ridge')
        bouton_3.pack(side= LEFT, padx= 5, pady=5, ipadx= 30)
     
        main_screen.mainloop()
     
     
    main_menu()

    Merci beaucoup et bonne journée.

  2. #2
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 302
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 302
    Points : 36 801
    Points
    36 801
    Par défaut
    Salut,

    Citation Envoyé par Tibo1920 Voir le message
    J'aimerai vraiment que ça switch de fenêtre, et non que ouvre juste l'autre par dessus.
    Vous pouvez écrire quelque chose de ce genre là:
    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
     
    import tkinter as tk
     
    root = tk.Tk()
     
    f0 = tk.Frame(root)
    f1 = tk.Frame(f0, width=200, height=400, bg='green')
    f2 = tk.Frame(f0, width=200, height=400, bg='red')
    f1.pack(side='left')
    f2.pack(side='left')
    f0.pack()
     
    f3 = tk.Frame(root, width=400, height=400, bg='grey')
     
    frames = [ f0, f3 ]
    index = 0
    def on_click(e):
        global index
        cf = frames[index]
        cf.pack_forget()
        index = (index+1) % len(frames)
        cf = frames[index]
        cf.pack()
     
    root.bind('<1>', on_click)
    root.mainloop()
    à adapter selon vos besoins.

    - W

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2020
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mars 2020
    Messages : 12
    Points : 9
    Points
    9
    Par défaut
    Bonjour,

    Merci pour votre réponse, je suis tomber sur une dizaine de code similaire mais je n'arrive pas à l'adapter à mon code.
    Car j'utilise la même Frame pour tous mes boutons, alors qu'avec le code envoyé il en faut un par boutons, mais peut être que je me trompe.

  4. #4
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 302
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 302
    Points : 36 801
    Points
    36 801
    Par défaut
    Salut,

    Si ce que vous voulez c'est "J'aimerai vraiment que ça switch de fenêtre, et non que ouvre juste l'autre par dessus."... c'est juste pas possible!

    On peut remplacer le contenu d'une fenêtre ou la détruire et en créer une ou des nouvelles. De plus, vous ne pouvez pas détruire la fenêtre principale ou en créer plusieurs sans de gros soucis.

    A vous d'adapter le code pour gérer ces contraintes.

    - W

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2020
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mars 2020
    Messages : 12
    Points : 9
    Points
    9
    Par défaut
    Bonjour, et merci pour vos précisions.

    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
    #coding:utf-8
     
    from tkinter import *
    import os
    import tkinter as tk
    import webbrowser 
    from tkinter import messagebox
    import subprocess
    import time
     
    class HoverButton(tk.Button):
        def __init__(self, master, **kw):
            tk.Button.__init__(self,master=master,**kw)
            self.defaultBackground = self["background"]
            self.bind("<Enter>", self.on_enter)
            self.bind("<Leave>", self.on_leave)
     
        def on_enter(self, e):
            self['background'] = self['activebackground']
     
        def on_leave(self, e):
            self['background'] = self.defaultBackground
     
     
    def raise_frame(frame):
        frame.tkraise()
     
    root = Tk()
    root.resizable(width=False, height=False)
    screenn_x = int(root.winfo_screenwidth())
    root.config(background='#1c2028')
    screenn_y = int(root.winfo_screenheight()) 
    root.title("ComboKit v0.0.1")
    windowss_x = 570
    windowss_y = 340
     
    possX = (screenn_x // 2) - (windowss_x // 2)
    possY = (screenn_y // 2) - (windowss_y // 2)
     
    geoo = "{}x{}+{}+{}".format(windowss_x, windowss_y, possX, possY)
    root.geometry(geoo)
     
    Main = Frame(root, bg='#1c2028')
    Anti_Duplicate = Frame(root, bg='#1c2028')
     
    for frame in (Main, Anti_Duplicate):
        frame.grid(row=0, column=0, sticky='news')
     
     
    bouton_1 = HoverButton(Main, font=("Arial", 15), text="Anti-Duplicate", background='#1c2028', fg='white',  borderwidth=2, activebackground= '#202124', activeforeground='#1195cf', relief='ridge', command=lambda:raise_frame(Anti_Duplicate)).pack()
     
    bouton_back1 = HoverButton(Anti_Duplicate, font=("Arial", 10), text="Back", background='#1c2028', fg='white',  borderwidth=2, activebackground= '#202124', activeforeground='#1195cf', relief='ridge', command=lambda:raise_frame(Main)).pack()
     
    raise_frame(Main)
    root.mainloop()
    Nom : Screenshot_1.png
Affichages : 900
Taille : 5,1 Ko

    Nom : Screenshot_2.png
Affichages : 865
Taille : 8,3 Ko

    Auriez vous une idée de comment placer les objets indépendamment ?
    Parce que là ils sont au même endroit, à cause de
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    for frame in (Main, Anti_Duplicate):
        frame.grid(row=0, column=0, sticky='news')

    Merci encore une fois

  6. #6
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 302
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 302
    Points : 36 801
    Points
    36 801
    Par défaut
    Citation Envoyé par Tibo1920 Voir le message
    Auriez vous une idée de comment placer les objets indépendamment ?
    Parce que là ils sont au même endroit, à cause de
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    for frame in (Main, Anti_Duplicate):
        frame.grid(row=0, column=0, sticky='news')
    Si vous affichez un widget dans la case 0, 0 et un autre widget dans la même case, ils seront au même endroit... Et si vous voulez autre chose, je ne comprends pas trop la difficulté.

    - W

  7. #7
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2020
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mars 2020
    Messages : 12
    Points : 9
    Points
    9
    Par défaut
    Citation Envoyé par wiztricks Voir le message
    Si vous affichez un widget dans la case 0, 0 et un autre widget dans la même case, ils seront au même endroit... Et si vous voulez autre chose, je ne comprends pas trop la difficulté.

    - W
    Re,

    Du coup j'ai fais autrement, mais bien évidemment il a fallu que je rencontre un problème.



    Du coup jusque là tout vas bien, j'ai réussi à ouvrir mon autre fenêtre, maintenant mon but est d'ouvrir un fichier texte, sauf que lors de l’exécution la premier fenêtre repasse devant, vous comprendrez mieux avec la vidéo:



    Désolé pour toutes ses questions je débute vraiment et je fais comme je peux...

  8. #8
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 302
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 302
    Points : 36 801
    Points
    36 801
    Par défaut
    Salut,

    Sans poster le code qui pose problème....

    - W

  9. #9
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2020
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mars 2020
    Messages : 12
    Points : 9
    Points
    9
    Par défaut
    Citation Envoyé par wiztricks Voir le message
    Salut,

    Sans poster le code qui pose problème....

    - W
    Autant pour moi...

    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
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    #coding:utf-8
     
    from tkinter import *
    import os
    import tkinter as tk
    import webbrowser 
    from tkinter import messagebox
    import subprocess
    import time
    from tkinter import ttk
    from tkinter.filedialog import askopenfilename
     
    #----------------------------------------------------------
     
    #Ouverture fichier
     
    def OpenFile1():
        name1 = askopenfilename(initialdir="/",
                               filetypes =(("Text File", "*.txt"),("All Files","*.*")),
                               title = "Choose a file."
                               )
        print (name1)
        #Using try in case user types in unknown file or closes without choosing a file.
        try:
            with open(name1,'r') as UseFile:
                print(name1)
        except:
            print("No file exists")
     
    #----------------------------------------------------------
     
    #Customisation Bouton
     
    class HoverButton(tk.Button):
        def __init__(self, master, **kw):
            tk.Button.__init__(self,master=master,**kw)
            self.defaultBackground = self["background"]
            self.bind("<Enter>", self.on_enter)
            self.bind("<Leave>", self.on_leave)
     
        def on_enter(self, e):
            self['background'] = self['activebackground']
     
        def on_leave(self, e):
            self['background'] = self.defaultBackground
     
    #----------------------------------------------------------
     
    #Menu Anti_Duplicate
     
    def Anti_Duplicate():
     
        global Anti_Duplicate
        A_Duplicate = Tk()
        A_Duplicate.resizable(width=False, height=False)
        screenn_x = int(A_Duplicate.winfo_screenwidth())
        A_Duplicate.config(background='#1c2028')
        screenn_y = int(A_Duplicate.winfo_screenheight()) 
        A_Duplicate.title("Anti-Duplicate v0.0.1")
        windowss_x = 570
        windowss_y = 340
     
        possX = (screenn_x // 2) - (windowss_x // 2)
        possY = (screenn_y // 2) - (windowss_y // 2)
     
        geoo = "{}x{}+{}+{}".format(windowss_x, windowss_y, possX, possY)
        A_Duplicate.geometry(geoo)
     
        mainframe = Frame(A_Duplicate, bg='#1c2028')
        mainframe.pack(side= TOP, ipadx= 5, ipady= 5)
     
        bouton_1 = HoverButton(A_Duplicate, font=("Arial", 10), text="Back", background='#1c2028', fg='white',  borderwidth=2, activebackground= '#202124', activeforeground='#1195cf', relief='ridge', command= A_Duplicate.destroy)
        bouton_1.place(x=520, y=300)
     
        open_button = HoverButton(A_Duplicate, font=("Arial", 10), text="Ouvrir un fichier..", background='#1c2028', fg='white',  borderwidth=2, activebackground= '#202124', activeforeground='#1195cf', relief='ridge', command= OpenFile1)
        open_button.place(x=229.5, y=200)
     
        bouton_2 = Button(A_Duplicate, font=("Arial", 10), text="Cet outil a pour but de supprimer les lignes en double d'un fichier texte.",  background='#202124', fg='#1195cf',  borderwidth=2, activebackground= '#202124', activeforeground='#1195cf', relief='sunken')
        bouton_2.place(x=75.5, y=50)
     
        bouton_1 = Button(mainframe, font=("Arial", 15), text="Anti-Duplicate", background='#202124', fg='#1195cf',  borderwidth=2, activebackground= '#202124', activeforeground='#1195cf', relief='sunken')
        bouton_1.pack(padx= 5, pady=10, ipadx= 30)
     
     
    # Menu Split
     
    def Split():
     
        global Split
        Split_Window = Tk()
        Split_Window.resizable(width=False, height=False)
        screenn_x = int(Split_Window.winfo_screenwidth())
        Split_Window.config(background='#1c2028')
        screenn_y = int(Split_Window.winfo_screenheight()) 
        Split_Window.title("Split v0.0.1")
        windowss_x = 570
        windowss_y = 340
     
        possX = (screenn_x // 2) - (windowss_x // 2)
        possY = (screenn_y // 2) - (windowss_y // 2)
     
        geoo = "{}x{}+{}+{}".format(windowss_x, windowss_y, possX, possY)
        Split_Window.geometry(geoo)
     
        mainframe = Frame(Split_Window, bg='#1c2028')
        mainframe.pack(side= TOP, ipadx= 5, ipady= 5)
     
        bouton_1 = HoverButton(Split_Window, font=("Arial", 10), text="Back", background='#1c2028', fg='white',  borderwidth=2, activebackground= '#202124', activeforeground='#1195cf', relief='ridge', command= Split_Window.destroy)
        bouton_1.place(x=520, y=300)
     
        open_button = HoverButton(Split_Window, font=("Arial", 10), text="Ouvrir un fichier..", background='#1c2028', fg='white',  borderwidth=2, activebackground= '#202124', activeforeground='#1195cf', relief='ridge', command= OpenFile1)
        open_button.place(x=229.5, y=200)
     
        bouton_2 = Button(Split_Window, font=("Arial", 10), text="Cet outil a pour but de diviser un fichier texte, selon un nombre de lignes donné.",  background='#202124', fg='#1195cf',  borderwidth=2, activebackground= '#202124', activeforeground='#1195cf', relief='sunken')
        bouton_2.place(x=50, y=50)
     
        bouton_1 = Button(mainframe, font=("Arial", 15), text="Split", background='#202124', fg='#1195cf',  borderwidth=2, activebackground= '#202124', activeforeground='#1195cf', relief='sunken')
        bouton_1.pack(padx= 5, pady=10, ipadx= 30)
     
     
    # Menu Fusion
     
    def Fusion():
     
        global Fusion
        Fusion_Window = Tk()
        Fusion_Window.resizable(width=False, height=False)
        screenn_x = int(Fusion_Window.winfo_screenwidth())
        Fusion_Window.config(background='#1c2028')
        screenn_y = int(Fusion_Window.winfo_screenheight()) 
        Fusion_Window.title("Fusion v0.0.1")
        windowss_x = 570
        windowss_y = 340
     
     
        possX = (screenn_x // 2) - (windowss_x // 2)
        possY = (screenn_y // 2) - (windowss_y // 2)
     
        geoo = "{}x{}+{}+{}".format(windowss_x, windowss_y, possX, possY)
        Fusion_Window.geometry(geoo)
     
        mainframe = Frame(Fusion_Window, bg='#1c2028')
        mainframe.pack(side= TOP, ipadx= 5, ipady= 5)
     
        bouton_1 = HoverButton(Fusion_Window, font=("Arial", 10), text="Back", background='#1c2028', fg='white',  borderwidth=2, activebackground= '#202124', activeforeground='#1195cf', relief='ridge', command= Fusion_Window.destroy)
        bouton_1.place(x=520, y=300)
     
        bouton_1 = Button(mainframe, font=("Arial", 15), text="Fusion", background='#202124', fg='#1195cf',  borderwidth=2, activebackground= '#202124', activeforeground='#1195cf', relief='sunken')
        bouton_1.pack(padx= 5, pady=10, ipadx= 30)
     
     
     
     
     
    #Menu principal 
     
     
    def main_menu():
        global main_menu
     
        main_screen = Tk()
        main_screen.resizable(width=False, height=False)
        screenn_x = int(main_screen.winfo_screenwidth())
        main_screen.config(background='#1c2028')
        screenn_y = int(main_screen.winfo_screenheight()) 
        main_screen.title("ComboKit v0.0.1")
        windowss_x = 570
        windowss_y = 340
     
        possX = (screenn_x // 2) - (windowss_x // 2)
        possY = (screenn_y // 2) - (windowss_y // 2)
     
        geoo = "{}x{}+{}+{}".format(windowss_x, windowss_y, possX, possY)
        main_screen.geometry(geoo)
     
        mainframe = Frame(main_screen, bg='#1c2028')
        mainframe.pack(side= TOP, ipadx= 5, ipady= 5)
     
        bouton_1 = HoverButton(mainframe, font=("Arial", 15), text="Fusion", background='#1c2028', fg='white',  borderwidth=2, activebackground= '#202124', activeforeground='#1195cf', relief='ridge', command=Fusion)
        bouton_1.pack(side= LEFT, padx= 5, pady=5, ipadx= 30)
     
        bouton_2 = HoverButton(mainframe, font=("Arial", 15), text="Anti-Duplicate", background='#1c2028', fg='white',  borderwidth=2, activebackground= '#202124', activeforeground='#1195cf', relief='ridge', command=Anti_Duplicate)
        bouton_2.pack(side= LEFT, padx= 5, pady=5, ipadx= 30)
     
        bouton_3 = HoverButton(mainframe, font=("Arial", 15), text="Split*", background='#1c2028', fg='white',  borderwidth=2, activebackground= '#202124', activeforeground='#1195cf', relief='ridge', command=Split)
        bouton_3.pack(side= LEFT, padx= 5, pady=5, ipadx= 30)
     
        main_screen.mainloop()
     
    main_menu()

    Merci encore.

  10. #10
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 302
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 302
    Points : 36 801
    Points
    36 801
    Par défaut
    Salut,

    Je ne vois pas pourquoi ce code là qui est plus gros que le premier mais construit suivant les mêmes principes (et ayant les mêmes défaut) fonctionnerait.

    Apprenez à faire la différence entre fenêtre principale (Tk) et fenêtre secondaire (Toplevel) et Frame (une collection de widget qu'on va pouvoir afficher dans une fenêtre). Essayez de comprendre l'exemple que je vous ai donné: on remplace juste la Frame dans la fenêtre principale.

    Et passez plus de temps à comprendre les mécanismes de tkinter qu'à rendre votre application jolie!
    Tant que vous n'aurez pas une mécanique fonctionnelle, il va falloir revoir le code. Le "joli", c'est des lignes de code qu'il faudra bouger en plus et qui n'ajoutent rien à la compréhension du problème.

    - W

  11. #11
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2020
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mars 2020
    Messages : 12
    Points : 9
    Points
    9
    Par défaut
    Bonjour,

    Merci de prendre part et d’essayer de m’aider.
    Comme dit plus haut je fais avec ce que je connais et je me base sur des tutoriels rapides sur Internet.
    J'ai vu rapidement ce qu’était (Top Level) et vous venez de me le préciser, je sais maintenant que c’est une fenêtre secondaire.
    Ça ne sert à rien de me rappeler que mon code est lourd/gros, je le fais avec mes connaissances je sais très bien qu’il pourrait être 100 fois optimisé mais je fais de mon possible.
    Merci pour votre bienveillance, je vais prendre en compte vos conseils, et faire de mon mieux.

  12. #12
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 302
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 302
    Points : 36 801
    Points
    36 801
    Par défaut
    Salut,

    Citation Envoyé par Tibo1920 Voir le message
    Ça ne sert à rien de me rappeler que mon code est lourd/gros, je le fais avec mes connaissances je sais très bien qu’il pourrait être 100 fois optimisé mais je fais de mon possible.
    Je ne vous demande pas d'optimiser quoi que ce soit, juste de vous concentrer sur les interactions que vous voulez réaliser. Pour afficher une Frame à la place d'une autre, inutile qu'elle contienne quoi que ce soit sauf peut être le Button qui forcera le changement.


    - W

  13. #13
    Invité
    Invité(e)
    Par défaut
    Citation Envoyé par Tibo1920 Voir le message
    Bonjour,

    Merci de prendre part et d’essayer de m’aider.
    Comme dit plus haut je fais avec ce que je connais et je me base sur des tutoriels rapides sur Internet.
    J'ai vu rapidement ce qu’était (Top Level) et vous venez de me le préciser, je sais maintenant que c’est une fenêtre secondaire.
    Ça ne sert à rien de me rappeler que mon code est lourd/gros, je le fais avec mes connaissances je sais très bien qu’il pourrait être 100 fois optimisé mais je fais de mon possible.
    Merci pour votre bienveillance, je vais prendre en compte vos conseils, et faire de mon mieux.
    Bonjour ,

    En complément de l'exemple fourni plus haut, voici un autre exemple avec l'utilisation de boutons :

    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
    #_*_coding: utf-8_*_
     
    import tkinter as Tk
     
    fen = Tk.Tk()
    frame_accueil = Tk.LabelFrame(
        fen, text="frame1", width=200, height=400, background="red")
    frame_accueil.pack(side=Tk.LEFT)
    frame_suivante = Tk.LabelFrame(
        fen, text="frame2", width=200, height=400, background="blue")
    frame_suivante.pack(side=Tk.LEFT)
    Tk.Button(fen, text="cacher frame1",
              command=lambda : frame_accueil.pack_forget()).pack(side=Tk.BOTTOM)
    Tk.Button(fen, text="afficher frame1",
              command=lambda : frame_accueil.pack(side=Tk.LEFT)).pack(side=Tk.BOTTOM)
    Tk.Button(fen, text="cacher frame2",
              command=lambda : frame_suivante.pack_forget()).pack(side=Tk.BOTTOM)
    Tk.Button(fen, text="afficher frame2",
              command=lambda : frame_suivante.pack(side=Tk.LEFT)).pack(side=Tk.BOTTOM)
    fen.mainloop()
    Ce code peut être adapté avec utilisation de fonctions, class. L'intérêt c'est de comprendre les possibilités de la bibliothèque tkinter.
    Les fenêtre et les frames restent des conteneurs dans lesquels nous placez d'autres widgets.
    Comme vous l'a si bien expliqué wiztricks, qui me reprendra si je me trompe, on peut jouer avec toutes les frames (masquer, afficher, supprimer), contrairement aux fenêtres où la fenêtre principale doit rester ouverte.
    Nhésitez pas à faire des tests, c'est très instructif.
    Voici un lien vers une documentation très bien faite :
    http://tkinter.fdex.eu/index.html

Discussions similaires

  1. Problème pour l'ouverture d'une fenêtre tkinter
    Par Invité dans le forum Général Python
    Réponses: 9
    Dernier message: 11/04/2014, 12h44
  2. créer fenêtre Tkinter
    Par hyuga33 dans le forum Tkinter
    Réponses: 7
    Dernier message: 15/05/2010, 21h33
  3. Réponses: 2
    Dernier message: 29/04/2010, 07h46
  4. Problème de fenêtres Tkinter
    Par nicogigo dans le forum Tkinter
    Réponses: 2
    Dernier message: 04/04/2010, 04h39
  5. PLusieurs fenêtre Tkinter
    Par peyro dans le forum Tkinter
    Réponses: 2
    Dernier message: 14/06/2006, 15h04

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