Bonjour, j'ai récupérer un script python, et je suis en train de l'adapter pour un projet.

J'ai réussi à dimensionner les frames, mettre de la couleur, du texte, mais je ne trouve pas pour le centrage à l'écran.
j'ai testé de différentes façons mais pas réussi.

Pourrais-je avoir de l'aide svp?

Voici mon 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
try:
    import Tkinter as tk
except:
    import tkinter as tk
#root = tk.Tk()
 
 
classSampleApp(tk.Tk):
    def__init__(self):
        tk.Tk.__init__(self)
        self._frame = None
self.switch_frame(StartPage)
#self.geometry("%dx%d%+d%+d" % (l,h,(tk.winfo_screenwidth()-l)//2,(tk.winfo_screenheight()-h)//2))
#x_cordinate = int((screen_width/2) - (window_width/2))
#y_cordinate = int((screen_height/2) - (window_height/2))
#screen_width = tk.winfo_screenwidth()
#screen_height = tk.winfo_screenheight()
#self.master.geometry("{}x{}+{}+{}".format(window_width, window_height, x_cordinate, y_cordinate))
defswitch_frame(self, frame_class):
        new_frame = frame_class(self)
        ifself._frame isnotNone:
            self._frame.destroy()
        self._frame = new_frame
        self._frame.pack()
 
    #def centrefenetre(fen):
#fen.update_idletasks()
#l,h,x,y=geoliste(fen.geometry())
#fen.geometry("%dx%d%+d%+d" % (l,h,(fen.winfo_screenwidth()-l)//2,(fen.winfo_screenheight()-h)//2))
 
classStartPage(tk.Frame):
    def__init__(self, master):
        tk.Frame.__init__(self, master)
        self.master.title("StartPage")
        tk.Label(self, text="Choisissez l'action à executer.", font=("Helvetica", 18, "bold")).pack(
            side="top", fill="x", pady=20, padx=60
        )
 
        tk.Button(
            self, text="Go to page one", command=lambda: master.switch_frame(PageOne)
        ).pack(side="left",padx=15, pady=6)
        tk.Button(
            self, text="Go to page two", command=lambda: master.switch_frame(PageTwo)
        ).pack(side="right",padx=15, pady=6)
 
classPageOne(tk.Frame):
    def__init__(self, master):
        tk.Frame.__init__(self, master)
        tk.Frame.configure(self, bg="green")
        tk.Label(self, text="vous avez choisi la page One", font=("Helvetica", 18, "bold")).pack(
            side="top", fill="x", pady=20, padx=60
        )
        self.master.title("PageOne ")
        tk.Button(
            self,
            text="Go back to start page",
            command=lambda: master.switch_frame(StartPage),
        ).pack(side="top",padx=15, pady=6)
 
classPageTwo(tk.Frame):
    def__init__(self, master):
        tk.Frame.__init__(self, master)
        tk.Frame.configure(self, bg="red")
        tk.Label(self, text="vous avez choisi la page two", font=("Helvetica", 18, "bold")).pack(
            side="top", fill="x", pady=20, padx=60
        )
        self.master.title("PageTow")
        tk.Button(
            self,
            text="Go back to start page",
            command=lambda: master.switch_frame(StartPage),
        ).pack(side="top",padx=15, pady=6)
 
if__name__ == "__main__":
    app = SampleApp()
    app.mainloop()
-
Edité par JeanMarcCollin1 il y a 20 minutes