""" History GUI button component. """ from tkinter import * from functools import partial # To prevent unwanted windows class Converter: """ Temperature conversion tool (C to F or F to C) """ def __init__(self): """ Temperature converter GUI """ self.temp_frame = Frame(padx=10, pady=10) self.temp_frame.grid() self.to_history_button = Button(self.temp_frame, text="Help / Info", bg="#CC6600", fg="#FFFFFF", font=("Arial", "14", "bold"), width=12, command=self.to_history) self.to_history_button.grid(row=1, padx=5, pady=5) def to_history(self): """ Opens help dialogue box and disables help button (so that users can't create multiple help boxes). """ HistoryExport(self) class HistoryExport: """ Displays help window """ def __init__(self, partner): # setup dialogue box and background colour background = "#ffe6cc" self.history_box = Toplevel() # disable help button partner.to_history_button.config(state=DISABLED) self.history_box.protocol('WM_DELETE_WINDOW', partial(self.close_history, partner)) self.history_frame = Frame(self.history_box, width=300, height=200) self.history_frame.grid() self.history_heading_label = Label(self.history_frame, text="History / Export", font=("Arial", "14", "bold")) self.history_heading_label.grid(row=0) history_text = "Below are your recent calculations - showing 3 / 3 calculations. " \ "All calculations are shown to the nearest degree." self.history_text_label = Label(self.history_frame, text=history_text, wraplength=350, justify="left") self.history_text_label.grid(row=1, padx=10) # calculation list goes here history_instructions_text = "Please push the Export button to save your calculations in a text file. " \ "If the file name already exists, it will be overwritten!" self.history_instructions_label = Label(self.history_frame, text=history_instructions_text, wraplength=350, justify="left") self.history_instructions_label.grid(row=2, padx=10) self.history_button_frame = Frame(self.history_frame) self.history_button_frame.grid(row=4) self.dismiss_button = Button(self.history_button_frame, font=("Arial", "12", "bold"), text="Export", bg="#0000FF", fg="#FFFFFF", command=partial(self.close_history, partner)) self.dismiss_button.grid(row=3, column=0, padx=0, pady=0) self.dismiss_button = Button(self.history_button_frame, font=("Arial", "12", "bold"), text="Dismiss", bg="#808080", fg="#FFFFFF", command=partial(self.close_history, partner)) self.dismiss_button.grid(row=3, column=1, padx=5, pady=5) # List and loop to set background colour on # everything except the buttons. recolour_list = [self.history_frame, self.history_heading_label, self.history_text_label, self.history_instructions_label, self.history_button_frame] for item in recolour_list: item.config(bg=background) def close_history(self, partner): partner.to_history_button.config(state=NORMAL) self.history_box.destroy() if __name__ == "__main__": root = Tk() root.title("Temperature Converter") Converter() root.mainloop()