Registar Sexo
escolha =True
while escolha ==True:
sexo = str(input("Informe o seu sexo:[M/F] ")).strip().upper()[0]
if sexo not in "MF":
print("Informação Errada!")
elif sexo =="M":
print("O sexo registrado foi: Masculino.")
else:
print("O sexo registrado foi: Feminino.")
# VersãoTkinter
from tkinter import *
root = Tk()
root.geometry("400x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Escolha de Sexo")
titulo = Label(text="Escolha de Sexo",
font=("Arial", "28", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.08, rely=0.05)
def app():
v = sexo.get()
if v == 1:
resultado_texto.config(text="O sexo registrado foi: Masculino.")
elif v == 2:
resultado_texto.config(text="O sexo registrado foi: Feminino.")
sexo = IntVar()
masculino = Radiobutton(root, text="Masculino", font=("Arial", "18", "bold"), bg="white", fg="#103030",
variable=sexo, value=1, command=app)
masculino.place(relx=0.25, rely=0.25)
feminino = Radiobutton(root, text="Feminino", font=("Arial", "18", "bold"), bg="white", fg="#103030",
variable=sexo, value=2, command=app)
feminino.place(relx=0.25, rely=0.45)
resultado_texto = Label(text="", font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.8, relwidth=0.9, relheight=0.15)
root.mainloop()
# Outra versão Tkinter
from tkinter import *
from tkinter import messagebox
def app():
selected_options = []
if CheckVar1.get() == 1:
selected_options.append("Masculino")
if CheckVar2.get() == 1:
selected_options.append("Feminino")
if selected_options:
message = "Selecionou: " + ", ".join(selected_options)
else:
message = "Não foi selecionado nenhuma hipótese."
messagebox.showinfo("Escolha", message)
root = Tk()
root.title("Selecionado")
root.geometry("300x200")
CheckVar1 = IntVar()
CheckVar2 = IntVar()
C1 = Checkbutton(root, text="Masculino", variable=CheckVar1,
onvalue=1, offvalue=0, height=2, width=20)
C1.place(relx=0.15,rely=0.15)
C2 = Checkbutton(root, text="Feminino", variable=CheckVar2,
onvalue=1, offvalue=0, height=2, width=20)
C2.place(relx=0.15,rely=0.35)
show_button = Button(root, text="Mostrar a Escolha", command=app)
show_button.place(relx=0.15,rely=0.7,relwidth=0.4)
root.mainloop()
Comentários
Enviar um comentário