import csv import random from tkinter import * from functools import partial # To prevent unwanted windows class StartGame: """ Initial Game interface (asks users how many rounds they would like to play) """ def __init__(self): # Gets number of rounds from user self.start_frame = Frame(padx=10, pady=10) self.start_frame.grid() # create play button self.play_button = Button(self.start_frame, font=("Arial", "16"), fg="#FFFFFF", bg="#0057D8", text="Play", width=10, command=self.check_rounds) self.play_button.grid(row=0, column=1, padx=20, pady=20) def check_rounds(self): """ Checks users have entered 1 or more rounds """ # Retrieve number of rounds to be played rounds_wanted = 5 # placeholder value self.to_play(rounds_wanted) def to_play(self, num_rounds): """ Invokes Game GUI and passes across number of rounds to be played. """ Play(num_rounds) # Hide root window (ie: hide rounds choice window). root.withdraw() class Play: """ Interface for playing the Colour Quest Game """ def __init__(self, how_many): self.play_box = Toplevel() self.game_frame = Frame(self.play_box) self.game_frame.grid(padx=10, pady=10) self.heading_label = Label(self.game_frame, text="Colour Quest", font=("Arial", "16", "bold"), padx=5, pady=5) self.heading_label.grid(row=0) self.hints_button = Button(self.game_frame, font=("Arial", "14", "bold"), text="Hints", width=15, fg="#FFFFFF", bg="#FF8000", padx=10, pady=10, command=self.to_hints) self.hints_button.grid(row=1) def to_hints(self): """ Display hints for playing game """ DisplayHints(self) class DisplayHints: """ Displays hints for Colour Quest Game """ def __init__(self, partner): # setup dialogue box and background colour background = "#ffe6cc" self.hints_box = Toplevel() # disable hints button partner.to_hints_button.config(state=DISABLED) # If users press the cross at the top, close hints and # 'release' the hints button self.hints_box.protocol("WM_DELETE_WINDOW", partial(self.close_hints, partner)) self.hints_frame = Frame(self.hints_box, width=300, height=200, ) self.hints_frame.grid() self.hints_heading_label = Label(self.hints_frame, text="hints / Info", font=("Arial", "14", "bold")) self.hints_heading_label.grid(row=0) hints_text = "To use the program, simply enter the temperature " \ "you wish to convert and then choose to convert " \ "to either degrees Celsius (centigrade) or " \ "Fahrenheit.. \n\n" \ " Note that -273 degrees C " \ "(-459 F) is absolute zero (the coldest possible " \ "temperature). If you try to convert a " \ "temperature that is less than -273 degrees C, " \ "you will get an error message. In\n\n " \ "To see your " \ "calculation history and export it to a text " \ "file, please click the 'History / Export' button." self.hints_text_label = Label(self.hints_frame, text=hints_text, wraplength=350, justify="left") self.hints_text_label.grid(row=1, padx=10) self.dismiss_button = Button(self.hints_frame, font=("Arial", "12", "bold"), text="Dismiss", bg="#CC6600", fg="#FFFFFF", command=partial(self.close_hints, partner)) self.dismiss_button.grid(row=2, padx=10, pady=10) # List and loop to set background colour on # everything except the buttons. recolour_list = [self.hints_frame, self.hints_heading_label, self.hints_text_label] for item in recolour_list: item.config(bg=background) def close_hints(self, partner): """ Closes hints dialogue box (and enables hints button """ # put hints button back to normal... partner.to_hints_button.config(state=NORMAL) self.hints_box.destroy()