[Solved] Python GUI – Calculator drop-down menu [closed]


It took some effort, but here goes:

from tkinter import *
from tkinter.ttk import *

def left_side():
    """Left """
    global left_entry, right_entry, answer_label, integer_combo
    left_entry.get()

def right_side():
    """Right"""
    global left_entry, right_entry, answer_label, integer_combo
    right_entry.get()

def combo_calc():
    """Combobox basic Calculator"""
    global left_entry, right_entry, answer_label, integer_combo

    if integer_combo.get() == "+":
        answer_label['text'] = str(int(left_entry.get()) + int(right_entry.get()))
    elif integer_combo.get() == "-":
        answer_label['text'] = str(int(left_entry.get()) - int(right_entry.get()))
    elif integer_combo.get() == "*":
        answer_label['text'] = str(int(left_entry.get()) * int(right_entry.get()))

def main():
    """Runs the main GUI"""
    global left_entry, right_entry, answer_label, integer_combo

    window = Tk()
    integer_options = ["+", "-", "*"]
    integer_combo = Combobox(window,
                             values=integer_options)
    integer_combo.set("+")
    integer_combo.grid(row=0, column=1)
    left_entry = Entry(window)
    left_entry.grid(row=0, column=0)
    right_entry = Entry(window)
    right_entry.grid(row=0, column=2)
    calc_button = Button(window, text="Calculate", command=combo_calc)
    calc_button.grid(row=1, column=1)
    equals_label = Label(window, text="=")
    equals_label.grid(row=0,column=3)
    answer_label = Label(window)
    answer_label.grid(row=0, column= 4)

    window.mainloop()
main()

solved Python GUI – Calculator drop-down menu [closed]