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

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre habitué
    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
    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 : 1411
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 : 1061
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
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 741
    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 741
    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
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  3. #3
    Membre habitué
    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
    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
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 741
    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 741
    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
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  5. #5
    Membre habitué
    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
    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 : 1029
Taille : 5,1 Ko

    Nom : Screenshot_2.png
Affichages : 991
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
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 741
    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 741
    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
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

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