Pergunta de Sim ou Não

def saudacao():
print("Olá Mundo!")

while True:
pergunta = input('Deseja sair? Digite "s" para Sim ou "n" para Não: ').lower()
if pergunta not in ['s', 'n']:
print('Por favor, responda "s" ou "n".')
elif pergunta == 's':
saudacao()
else:
print("Fim do Programa\nAdeus!")
break

 

# Usando Tkinter


from tkinter import *
from tkinter import messagebox
def funcao():
resposta = messagebox.askyesno("Fechar Programa", "Você deseja realmente sair?")
if resposta:
root.quit()
root =Tk()
root.title("Entrada de Texto carregar depois de carregar no Butão'")
root.geometry("550x200")
root.config(bg="#2895a8")
botao_funcao = Button(text="Fechar", command=funcao,font=("Arial", "15", "bold"),bg="#d9ead3",fg="#bf9000")
botao_funcao.place(relx=0.3,rely=0.25,relwidth=0.4,relheight=0.25)
root.mainloop()

#Outras Versões


from tkinter import *
from tkinter import messagebox

root = Tk()
root.geometry("400x300")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Pergunta Sim ou Não")
titulo = Label(text="Pergunta Sim ou Não",
font=("Arial", "26", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.08, rely=0.05)

def sim():
resposta = messagebox.showinfo("Informação", "Carregou o Butão Sim")
def nao():
resposta = messagebox.showinfo("Informação", "Carregou o Butão Não")




but1 = Button(text="Sim", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=sim)
but1.place(relx=0.25, rely=0.35, relwidth=0.5, relheight=0.1)

but2 = Button(text="Não", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=nao)
but2.place(relx=0.25, rely=0.65, relwidth=0.5, relheight=0.1)


root.mainloop()

# Outra versão


while True:
resposta = input("Você deseja continuar?\n"
" [s] - Sim \n [n] - Não\n Escolha a opção: ").strip().lower()
if resposta == "sim" or resposta == "s":
print("Você escolheu continuar!")
# Adicione o que deseja fazer ao continuar
elif resposta == "não" or resposta == "n":
print("Você escolheu sair!")
break
else:
print("Resposta inválida!")

Comentários

Mensagens populares deste blogue

Criar Cartões de Visita

12 signos egípcios

Calcular a percentagem de ocupação