0

i tried to make a simple code to do a joke with my friends. It's based in: they entry with her names, and when they clicked in button, a answer appears. Before this, i maked a simple code based in: if(xxxx), so print(xxxxx). Now, i using tkinter to give a GUI to my code. But, i don't know how make the button do this when i push him.


from tkinter import *

def piadinhas():
    nome = input('Say your name! ')
    if nome == 'Fabricia' or nome == 'fabricia':
        print('*****************')
    elif nome == 'Roberto' or nome == 'roberto':
        print('Para de camperar na caixa da B')
    elif nome == 'Lucas' or nome == 'lucas':
        print('Oi, mozão!')
    elif nome == 'Leonardo' or nome == 'leonardo':
        print('Porque você não planta *********************?')
    elif nome == 'Montanha' or nome == 'montanha':
        print('Seu nome é montanha, ******?')
    elif nome == 'Marcos' or nome == 'marcos' or nome == 'Marcos Cesar':
        print('SOCRAAAAAAAAAAAAAAAAAAAAAAAAM, e aquela festinha lá, hein!?')
    elif nome == 'Lorenzo' or nome == 'lorenzo' or nome == 'oznerol':
        print('Qual o seu dom?')
    elif nome == 'Camiran':
        print('Quando será o próximo meme de marea pegando fogo?')
    else:
        print('Você não é um dos ****!')


janela = Tk()
janela.title('Aplicativo de Adjetivos Carinhosos')
janela.geometry('300x300')
janela.config(background='#dde')

texto_apresentacao = Label(janela, text='Eu sei quem você é!', background='#dde')
texto_apresentacao.grid(column=0, row=0, padx=85, pady=15)
texto_orientacao = Label(janela, text='Say Your Name, Dont Lie', background='#dde')
texto_orientacao.grid(column=0, row=1, padx=85, pady=15)

entrada_nome = Entry(janela)
entrada_nome.grid(column=0, row=2, padx=85, pady=15)

botao_resultado = Button(janela, width=20, height=2)

botao_resultado.grid(column=0, row=3, padx=85, pady=15)


janela.mainloop()

Who can help a poor beginner?

1 Answers1

1

You should have done a little research before asking. Learn about how-to-ask. And Refer here to know about the Entry widget in Tkinter.

Declare a string variable (needed to store the user's input.) Then, make that string variable as the Entry box's textvariable. And, set "command=piadinhas" so that the function is called on clicking that button.

inp = StringVar()
entrada_nome = Entry(janela,textvariable = inp)
...

botao_resultado = Button(janela, width=20, height=2, command=piadinhas)

Also, make these changes in your function:

def piadinhas():
    nome = inp.get()

Read the documentation to know more.

Kartikeya
  • 818
  • 2
  • 6
  • 11
  • you should probably leave links to the documentation, to help future visitors, just a suggestion. <3 Great answer. – typedecker Mar 01 '22 at 14:13
  • I'm sorry it took so long, but it worked fine. I'm having trouble compiling with auto py to exe, but I'll take a look before submitting new question. Thank you. – DennisMonteiro Mar 11 '22 at 04:10