Python app immediately closes after OptionMenu being clicked

52 Views Asked by At

EDIT: I found out that the program crashes when Message Box is called. Any solution? I am using Mac OS

I am creating a sales app in Python, I have a OptionMenu to select the form of payment. Most of the time as soon as the OptionMenu is clicked, all the app closes immediately without error message on the terminal. The weirdest thing is that sometimes it works correctly, but 80% of the time it closes all the app.

class MasterFacturacion():

  def CreateWidgets(self):
    
    self.payment_list = ['EFECTIVO', 'DEBITO', 'MERCADO PAGO', 'CREDITO']
    self.variable = tk.StringVar()
    self.variable.set("EFECTIVO")

    # creating widget
    self.dropdown = tk.OptionMenu(
        self.frame_izq,
        self.variable,
        *self.payment_list,
        command=self.change_color)

    self.dropdown.config(width=10)
    self.dropdown.config(height=2)
    self.dropdown.pack(padx=20, pady=10)

  def change_color(self, choice):
    choice = self.variable.get()
    if choice == "EFECTIVO":
      self.dropdown.config(bg="green")
    elif choice == "DEBITO":
      self.dropdown.config(bg="red")
    elif choice == "MERCADO PAGO":
      self.dropdown.config(bg="light blue")
    else:
      self.dropdown.config(bg="Blue")

I am working on Mac and using Visual Studio Code

0

There are 0 best solutions below