Bonjour à tous,
Voilà j'ai demandé à un membre fiver de me faire une interface graphique sur un projet mais il m'a planté sur la fin. il reste un bug d'affichage que je n'arrive pas à résoudre.

Nom : image_2024-02-02_184425015.png
Affichages : 252
Taille : 462,0 Ko

je ne connais pas le code python pour cela que je m'en remet à vous : Pouvez-vous m'aider SVP merci

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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
import tkinter as tk
from tkinter import ttk
from PIL import Image,ImageTk
import cv2
import imageio
import pyglet
#pyglet.font.add_file('digital-7.ttf')
import pyrebase
import firebase_admin
from firebase_admin import credentials
from firebase_admin import storage
 
config = {
  "apiKey": "",
  "authDomain": "",
  "databaseURL": "https:///",
  "storageBucket": ""
}
 
firebase_storage = pyrebase.initialize_app(config)
database = firebase_storage.database()
T_Red=0
T_Blue=0
ProjectBucket = database.child("game")
ProjectBucket.child("Next_Round").set(0)
ProjectBucket = database.child("game")
ProjectBucket.child("Start_Game").set(0)
ProjectBucket = database.child("game")
bluebutton = ProjectBucket.child("blueteam").get().val()
 
ProjectBucket = database.child("game")
R = ProjectBucket.child("Round").get().val()
 
ProjectBucket = database.child("game")
redbutton = ProjectBucket.child("RedTeam").get().val()
 
ProjectBucket = database.child("game")
G_time = ProjectBucket.child("Set_Timer").get().val()
print(G_time)
# Set initial values for blue and red teams
t=0
b=0
l=1
if l==1:
    def update_timer():
        print("update loop")
        l=1
        if l==1:
            global timer_seconds, current_round, timer_running
            timer_label.config(text=f"{timer_seconds // 70}:{timer_seconds % 60:02}")
            # Update the current round label
            round_label.config(text=str(current_round))
            if timer_seconds > 0 and timer_running:
                timer_seconds -= 1
                bluebutton = ProjectBucket.child("game").child("blueteam").get().val()
                redbutton = ProjectBucket.child("game").child("RedTeam").get().val()
                print(redbutton)
                if redbutton==1:
                    ProjectBucket.child("game").child("RedTeam").set(0)
                    increase_score_1()
                if bluebutton == 1:
                    ProjectBucket.child("game").child("blueteam").set(0)
                    increase_score_2()
                window.after(1000, update_timer)
            elif timer_seconds == 0:
                declare_winner()
    def declare_winner():
        global current_round
        bc = "white"
        score_1 =T_Blue
        score_2 = T_Red
        if score_2 > score_1:
            winner_text = "Team Blue"
            winner_color = "blue"
            update_winning_rounds(team_blue_wins_label)
        elif score_1 > score_2:
            winner_text = "Team red"
            winner_color = "red"
            update_winning_rounds(team_red_wins_label)
        else:
            winner_text = f"Round is tie"
            winner_color = "black"
 
        # Create a label for the winner and place it based on the current set
        winner_label_set = tk.Label(window, text=winner_text, fg=winner_color, font=('digital-7 40 bold'), bg=bc)
        winner_label_set.place(relx=0.43, rely=0.855, width=300, height=70)  # Adjust the position for each set
 
        # Save the label reference in a list for later cleanup
        winner_labels.append(winner_label_set)
 
        # Save the result for the overall winner
        round_results.append(winner_color)
 
        # Display the winner's status
        window.update_idletasks()  # Ensure the label is updated before the next line
        reset_button.config(state=tk.NORMAL)  # Enable the "Reset Scores" button
        start_button.config(state=tk.NORMAL)  # Enable the "Start Timer" button
 
        # Check for overall winner after all sets
        if current_round == R:
            overall_winner = max(set(round_results), key=round_results.count)
            overall_winner_label.config(text=f"Overall Winner: {overall_winner}", fg="green")
            overall_winner_label.place(relx=0.4, rely=0.82, width=30, height=80)  # Adjust the position for the overall winner
            # Display the video window based on the overall winner
            display_video(overall_winner)
 
    def display_video(winner):
        video_window = tk.Toplevel()
        video_window.title("Video Display")
 
        if winner == "blue":
            video_path = "blue.mp4"  # Replace with the actual path of the video for Team Blue
        elif winner == "red":
            video_path = "red.mp4"  # Replace with the actual path of the video for Team Red
        else:
            video_path = "tie.mp4"  # Replace with the actual path of the video for Tie
        cap = cv2.VideoCapture(video_path)
        while True:
            ret, frame = cap.read()
            if not ret:
                break
 
            # Display the frame
            cv2.imshow("Video Display", frame)
 
            # Break the loop when the user closes the window
            if cv2.waitKey(25) & 0xFF == ord("q"):
                break
        # Release the video capture
        cap.release()
        # Close all OpenCV windows
        cv2.destroyAllWindows()
        video_window.destroy()
        current_wins=0
        window.destroy()
 
 
    def update_winning_rounds(winning_label):
        current_wins = int(winning_label.cget("text"))
        current_wins += 1
        winning_label.config(text=str(current_wins))
    def reset_scores():
        global timer_seconds, timer_running, current_round
        global T_Red
        global T_Blue
        T_Blue=0
        T_Red=0
        score_var_1.set("0")
        score_var_2.set("0")
 
        # Destroy previous winner labels
        for label in winner_labels:
            label.destroy()
 
        # Reset the timer and current round
        timer_seconds = G_time  # Set the timer to 1 minute for each round
        update_timer_label()  # Update the timer label
        timer_running = False
 
        current_round += 1
        if current_round > R:
            current_round = 1  # Reset to 1 after the 3rd round
        # Update the current round label
        round_label.config(text=str(current_round))
        start_button.config(state=tk.NORMAL)
        reset_button.config(state=tk.DISABLED)
 
        update_combined_score_label()
 
 
    # Add this function to update the timer label
    def update_timer_label():
        timer_label.config(text=f"{timer_seconds // 75}:{timer_seconds % 60:02}")
 
    def increase_score_2():
        global T_Red
        if timer_running:
            T_Red=T_Red+1
            # current_score = int(score_var_1.get())
            # new_score = current_score + 1
            # score_var_1.set(new_score)
            update_combined_score_label()
 
    def increase_score_1():
        if timer_running:
            global T_Blue
            T_Blue=T_Blue+1
            # current_score = int(score_var_2.get())
            # new_score = current_score + 1
            # score_var_2.set(new_score)
            update_combined_score_label()
            print(T_Blue)
 
    def update_combined_score_label():
        combined_score_label.config(text=f"{T_Blue} : {T_Red}")
 
    def start_timer():
        global timer_running
        if not timer_running:
            timer_running = True
            update_timer()
    def stop_timer():
        global timer_running
        timer_running = False
    while True:
        # Create the main window
        window = tk.Tk()
        #window.geometry("1024x768")
        #window.attributes('-fullscreen', True)
        window.title("Drone Soccer - Scoreboard")
        background_image = Image.open("Backg.jpeg")        
        background_image = background_image.resize((window.winfo_screenwidth(), window.winfo_screenheight()), Image.LANCZOS)
        background_photo = ImageTk.PhotoImage(background_image)
 
        canvas = tk.Canvas(window, width=window.winfo_screenwidth(), height=window.winfo_screenheight())
        canvas.pack(fill="both", expand=True)
 
        canvas.create_image(0, 0, image=background_photo, anchor="nw")
        score_var_1 = tk.StringVar()
        score_var_2 = tk.StringVar()
        score_var_1.set("0")
        score_var_2.set("0")
        combined_score_label = tk.Label(window, text="0 : 0", font=('digital-7 250 bold'), bg="white", fg="black")
        combined_score_label.place(relx=0.25, rely=0.38,  width=800, height=400)
        button_style = {"font": ("Arial", 12), "fg": "white", "width": 15, "height": 2}
 
 
        reset_button = tk.Button(window, text="Start Next Round", command=reset_scores, bg="lightgray", fg="black", font=("Arial", 24))
        reset_button.place_forget()
 
        style = ttk.Style()
        style.configure("TButton", padding=10, font=("Arial", 24), foreground="black", background="green", borderwidth=8, relief=tk.RAISED)
 
        start_button = ttk.Button(window, text="Start Timer", command=start_timer, style="TButton")
        #start_button.place(relx=0.83, rely=0.85)
        start_button.place_forget()
        timer_seconds = G_time
        current_round = 0
 
        timer_label = tk.Label(window, text="0:00", font=('digital-7 80 bold'), bg="white", fg="red")
        timer_label.place(relx=0.43, rely=0.13, width=230, height=70)
 
 
        round_label = tk.Label(window, text=str(current_round), bg="white", font=('digital-7 80 bold'), fg="black")
        round_label.place(relx=0.27, rely=0.13, width=100, height=80)
        winner_labels = []
        round_results = []
 
        team_blue_wins_label = tk.Label(window, text="0", font=('digital-7 80 bold'), bg="white", fg="Black")
        team_blue_wins_label.place(relx=0.856, rely=0.41, width=100, height=100)
 
        team_red_wins_label = tk.Label(window, text="0", font=('digital-7 80 bold'), bg="white", fg="Black")
        team_red_wins_label.place(relx=0.07, rely=0.42, width=100, height=80)
 
        overall_winner_label = tk.Label(window, text="Overall Winner: ", font=("Arial", 25), fg="green")
        overall_winner_label.place_forget()
        timer_running = False
        while True:
            window.update_idletasks()
            window.update()
 
            ProjectBucket = database.child("game")
            G_time = ProjectBucket.child("Set_Timer").get().val()
            ProjectBucket = database.child("game")
            R = ProjectBucket.child("Round").get().val()
            ProjectBucket = database.child("game")
            Stop = ProjectBucket.child("Stop_Timer").get().val()
            if Stop == 1:
                ProjectBucket = database.child("game")
                ProjectBucket.child("Stop_Timer").set(0)
                stop_timer()
            ProjectBucket = database.child("game")
            Next_Round = ProjectBucket.child("Next_Round").get().val()
            if Next_Round == 1:
                ProjectBucket = database.child("game")
                ProjectBucket.child("Next_Round").set(0)
                reset_scores()
            ProjectBucket = database.child("game")
            Start_Game = ProjectBucket.child("Start_Game").get().val()
            if Start_Game == 1:
                ProjectBucket = database.child("game")
                ProjectBucket.child("Start_Game").set(0)
                start_timer()
 
            #window.mainloop()