from tkinter import * root = Tk()
root.geometry("700x300")
root.resizable(0, 0)
root.config(bg="#FAFAD2")
root.title("Cintos do Judo") titulo = Label(text="Cintos do Judo",
font=("Arial", "28", "bold"), bg="#FAFAD2", fg="black")
titulo.place(relx=0.24, rely=0.05) var = StringVar() dropDownList = [
"Iniciante",
"Iniciante+",
"Intermediário",
"Intermediário+",
"Avançado",
"Pré-cinto preto",
"Cinto preto (1.º a 5.º Dan)",
"Mestre (6.º a 8.º Dan)",
"Grandes Mestres (9.º e 10.º Dan)",
] Label(text="Cor do Cinto:",
font=("Arial", "18", "bold"), bg="#FAFAD2", fg="black").place(relx=0.05, rely=0.55) canvas = Canvas(root, width=300, height=40, bg="#FAFAD2", highlightthickness=0)
canvas.place(relx=0.4, rely=0.55) def mostrar_cinto(cor1, cor2=None):
canvas.delete("all")
largura = 300
altura = 40
if cor2:
canvas.create_rectangle(0, 0, largura//2, altura, fill=cor1, outline="")
canvas.create_rectangle(largura//2, 0, largura, altura, fill=cor2, outline="")
else:
canvas.create_rectangle(0, 0, largura, altura, fill=cor1, outline="") def app(*args):
v = var.get()
if v == "Iniciante":
mostrar_cinto("white")
elif v == "Iniciante+":
mostrar_cinto("yellow")
elif v == "Intermediário":
mostrar_cinto("orange")
elif v == "Intermediário+":
mostrar_cinto("blue")
elif v == "Avançado":
mostrar_cinto("green")
elif v == "Pré-cinto preto":
mostrar_cinto("brown")
elif v == "Cinto preto (1.º a 5.º Dan)":
mostrar_cinto("black")
elif v == "Mestre (6.º a 8.º Dan)":
mostrar_cinto("red", "white") # coral
elif v == "Grandes Mestres (9.º e 10.º Dan)":
mostrar_cinto("red") # Dropdown
var.trace("w", app)
var.set(dropDownList[0]) dropdown = OptionMenu(root, var, *dropDownList)
dropdown.place(relx=0.13, rely=0.34, relwidth=0.7)
dropdown.config(background='#4682B4', foreground="#F5F5DC", font=("Arial", "18", "bold"))
dropdown["menu"].config(background="#4682B4", foreground="#F5F5DC", font=("Arial", "18", "bold")) app() root.mainloop()
# Outra Versão
from tkinter import * root = Tk()
root.geometry("700x300")
root.resizable(0, 0)
root.config(bg="#FAFAD2")
root.title("Cintos do Judo") titulo = Label(text="Cintos do Judo",
font=("Arial", "28", "bold"), bg="#FAFAD2", fg="black")
titulo.place(relx=0.24, rely=0.05) var = StringVar() dropDownList = [
"6º Kyu",
"Intermédio 1",
"5º Kyu",
"Intermédio 2",
"4º Kyu",
"Intermédio 3",
"3º Kyu",
"Intermédio 4",
"2º Kyu",
"Intermédio 5",
"1º Kyu",
"Cinto preto (1.º a 5.º Dan)",
"Mestre (6.º a 8.º Dan)",
"Grandes Mestres (9.º e 10.º Dan)",
] Label(text="Cor do Cinto:",
font=("Arial", "18", "bold"), bg="#FAFAD2", fg="black").place(relx=0.05, rely=0.55) canvas = Canvas(root, width=300, height=40, bg="#FAFAD2", highlightthickness=0)
canvas.place(relx=0.4, rely=0.55) def mostrar_cinto(cor1, cor2=None):
canvas.delete("all")
largura = 300
altura = 40
if cor2:
canvas.create_rectangle(0, 0, largura//2, altura, fill=cor1, outline="")
canvas.create_rectangle(largura//2, 0, largura, altura, fill=cor2, outline="")
else:
canvas.create_rectangle(0, 0, largura, altura, fill=cor1, outline="") def app(*args):
v = var.get()
if v == "6º Kyu":
mostrar_cinto("white")
elif v == "Intermédio 1":
mostrar_cinto("white","yellow")
elif v == "5º Kyu":
mostrar_cinto("yellow")
elif v == "Intermédio 2":
mostrar_cinto("yellow","orange")
elif v == "4º Kyu":
mostrar_cinto("orange")
elif v == "Intermédio 3":
mostrar_cinto("orange","green")
elif v == "3º Kyu":
mostrar_cinto("green")
elif v == "Intermédio 4":
mostrar_cinto("green", "blue")
elif v == "2º Kyu":
mostrar_cinto("blue")
elif v == "Intermédio 5":
mostrar_cinto("blue", "brown")
elif v == "1º Kyu":
mostrar_cinto("brown")
elif v == "Cinto preto (1.º a 5.º Dan)":
mostrar_cinto("black")
elif v == "Mestre (6.º a 8.º Dan)":
mostrar_cinto("red", "white") # coral
elif v == "Grandes Mestres (9.º e 10.º Dan)":
mostrar_cinto("red") var.trace("w", app)
var.set(dropDownList[0]) dropdown = OptionMenu(root, var, *dropDownList)
dropdown.place(relx=0.13, rely=0.34, relwidth=0.7)
dropdown.config(background='#4682B4', foreground="#F5F5DC", font=("Arial", "18", "bold"))
dropdown["menu"].config(background="#4682B4", foreground="#F5F5DC", font=("Arial", "18", "bold")) app() root.mainloop()