from tkinter import * import all_constant as c class Converter: def __init__(self): """ Multi-currency converter GUI - shows currency selection buttons. Conversion logic not yet implemented. """ self.all_calculations_list = [] # Tracks which currency is selected as From and To self.from_currency = None self.to_currency = None self.main_frame = Frame(padx=10, pady=10) self.main_frame.grid() self.heading = Label(self.main_frame, text="Currency Converter", font=("Arial", "16", "bold")) self.heading.grid(row=0) instructions = ("Select a FROM currency, then a TO currency, " "enter an amount and press Convert.") self.instructions = Label(self.main_frame, text=instructions, wraplength=300, width=45, justify="left") self.instructions.grid(row=1) # Currency selection buttons frame self.currency_frame = Frame(self.main_frame) self.currency_frame.grid(row=2, pady=5) # List of supported currencies self.currencies = c.CURRENCIES # Build one button per currency - store refs in dict for easy access self.currency_buttons = {} for i, currency in enumerate(self.currencies): btn = Button(self.currency_frame, text=currency, bg="#AAAAAA", fg="#FFFFFF", font=("Arial", "12", "bold"), width=6, command=lambda cur=currency: self.select_currency(cur)) btn.grid(row=0, column=i, padx=4, pady=4) self.currency_buttons[currency] = btn # Label showing current From / To selection self.selection_label = Label(self.main_frame, text="From: — To: —", font=("Arial", "11"), fg="#004C99") self.selection_label.grid(row=3) # Amount entry self.amount_entry = Entry(self.main_frame, font=("Arial", "14")) self.amount_entry.grid(row=4, padx=10, pady=10) # Answer / error label self.answer_error = Label(self.main_frame, text="Select currencies above to begin", fg="#004C99", font=("Arial", "13", "bold")) self.answer_error.grid(row=5) # Bottom buttons frame self.button_frame = Frame(self.main_frame) self.button_frame.grid(row=6) # button list (button text | bg colour | command | row | column) button_details_list = [ ["Convert", "#009900", "", 0, 0], ["Help / Info", "#CC6600", "", 0, 1], ["History / Export", "#004C99", "", 0, 2] ] self.button_ref_list = [] for item in button_details_list: btn = Button(self.button_frame, text=item[0], bg=item[1], fg="#FFFFFF", font=("Arial", "12", "bold"), width=14, command=item[2]) btn.grid(row=item[3], column=item[4], padx=5, pady=5) self.button_ref_list.append(btn) # Disable history and convert until ready self.convert_button = self.button_ref_list[0] self.convert_button.config(state=DISABLED) self.to_history_button = self.button_ref_list[2] self.to_history_button.config(state=DISABLED) def select_currency(self, currency): """ Handles currency button selection logic. First click sets From, second click sets To. If both already selected, resets and sets new From. Prevents selecting same currency for both From and To. """ # If both already selected, reset and start again if self.from_currency and self.to_currency: self.reset_selection() # If nothing selected yet, set as From if self.from_currency is None: self.from_currency = currency self.currency_buttons[currency].config(bg="#2D6A4F") # green = From self.update_selection_label() # If From already selected and user picks a different currency, set as To elif self.to_currency is None and currency != self.from_currency: self.to_currency = currency self.currency_buttons[currency].config(bg="#004C99") # blue = To self.update_selection_label() self.convert_button.config(state=NORMAL) def reset_selection(self): """ Clears From / To selections and resets all button colours. """ self.from_currency = None self.to_currency = None self.convert_button.config(state=DISABLED) # Reset all currency buttons to grey for btn in self.currency_buttons.values(): btn.config(bg="#AAAAAA") self.update_selection_label() def update_selection_label(self): """ Updates the From / To display label based on current selection. """ from_text = self.from_currency if self.from_currency else "—" to_text = self.to_currency if self.to_currency else "—" self.selection_label.config(text=f"From: {from_text} To: {to_text}") # main routine if __name__ == "__main__": root = Tk() root.title("Currency Converter") Converter() root.mainloop()