Mundo em Python

Simulador de sorteio dos playoffs da Champions

import random
from tkinter import * possibilidades = {
"Real Madrid": ["Benfica", "Bodø/Glimt"],
"Inter": ["Benfica", "Bodø/Glimt"],

"PSG": ["Monaco", "Qarabag"],
"Newcastle": ["Monaco", "Qarabag"],

"Juventus": ["Club Brugge", "Galatasaray"],
"Atlético de Madrid": ["Club Brugge", "Galatasaray"],

"Atalanta": ["Borussia Dortmund", "Olympiacos"],
"Bayer Leverkusen": ["Borussia Dortmund", "Olympiacos"]
} def sortear_playoffs(mapa):
while True:
restantes = set(time for lista in mapa.values() for time in lista)
confrontos = {}
seeds = list(mapa.keys())
random.shuffle(seeds) valido = True

for seed in seeds:
opcoes = [t for t in mapa[seed] if t in restantes] if not opcoes:
valido = False
break

adversario = random.choice(opcoes)
confrontos[seed] = adversario
restantes.remove(adversario) if valido:
return confrontos root = Tk()
root.geometry("700x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Simulador de sorteio dos playoffs da Champions") titulo = Label(
text="Simulador de sorteio dos playoffs da Champions",
font=("Arial", 20, "bold"),
bg="#103030",
fg="#49e3e3"
)
titulo.place(relx=0.05, rely=0.05) def limpar():
resultado_texto.config(text="") def app():
resultado = sortear_playoffs(possibilidades) texto = "SORTEIO DOS PLAYOFFS \n\n"
for seed, adv in resultado.items():
texto += f"{seed} x {adv}\n"

resultado_texto.config(text=texto)
but1 = Button(
text="Mostrar",
bd=2,
bg='#107db2',
fg='white',
font=('verdana', 12, 'bold'),
command=app
)
but1.place(relx=0.1, rely=0.25, relwidth=0.25, relheight=0.1) but_limpar = Button(
text="Limpar",
bd=2,
bg='#107db2',
fg='white',
font=('verdana', 12, 'bold'),
command=limpar
)
but_limpar.place(relx=0.4, rely=0.25, relwidth=0.25, relheight=0.1) but_sair = Button(
text="Sair",
bd=2,
bg='#107db2',
fg='white',
font=('verdana', 12, 'bold'),
command=root.destroy
)
but_sair.place(relx=0.7, rely=0.25, relwidth=0.25, relheight=0.1) resultado_texto = Label(
text="",
font=("Arial", 12, "bold"),
bg="#cfe2f3",
justify=LEFT,
anchor="nw"
)
resultado_texto.place(relx=0.05, rely=0.45, relwidth=0.9, relheight=0.5) root.mainloop()
0