Button does not call function correctly

1
from tkinter import *

class Application:

      def __init__(self, master=None):
          self.inicio = Frame(master)
          self.inicio.pack()
          self.msg = Label(self.inicio, text="Deseja exprimentar a versao input?")
          self.msg["font"] = ("Calibri", "9", "italic")
          self.msg.pack ()
          self.sim = Button(self.inicio)
          self.sim["text"] = "sim"
          self.sim["font"] = ("Calibri", "9")
          self.sim["width"] = 10
          self.sim.bind("<Button-1>", self.Verificar)
          self.sim.pack ()
          self.nao = Button(self.inicio)
          self.nao["text"] = "nao"
          self.nao["font"] = ("Calibri", "9")
          self.nao["width"] = 10
          self.nao.bind("<Button-2>", self.Verificar)
          self.nao.pack ()

      def Verificar(self, event):
          if self.msg["text"] == "Deseja exprimentar a versao input?":
              self.msg["text"] = "Bem vindo a versao de input"

          else:
              self.msg['text']='Deseja exprimentar a versao input?'

root = Tk()

Application(root)

root.mainloop()

Does anyone know how to load the 'Welcome to output' message?

    
asked by anonymous 07.06.2017 / 21:43

1 answer

1

In this section:

self.nao.bind("<Button-2>", self.Verificar)

<Button-2> refers to the middle mouse button (try your program as it is by clicking the middle button).

Without messing around with your program, I would add a new function:

  def Verificar(self, event): # removi o else dessa
          self.msg["text"] = "Bem vindo a versao de input"
  def Verificar2(self, event): # função nova
          self.msg["text"] = "Bem vindo a versao de output"

And I would change the code of the button nao to <Button-1> too:

self.nao.bind("<Button-1>", self.Verificar2)
  

This should do what you want by using the correct buttons ...)

    
07.06.2017 / 22:37