Exemple #1
0
    def custom_game(self):

        #change the width, height, and total_mine value and soft initialize the game (without reinitialize all stuff)
        def return_custom():
            self.width, self.height, self.total_mine = int(
                width_input.get()), int(height_input.get()), int(
                    bomb_amount_input.get())
            custom_prompt.destroy()
            self.cleanup(difficulty=3)

        #initialize the prompt window (I used a themed window so it looks better)
        custom_prompt = ThemedTk(theme='breeze')
        custom_prompt.geometry('265x166')
        custom_prompt.title('Custom')
        custom_prompt.focus_force()

        #initialize all the widget inside the window
        height_label = ttk.Label(custom_prompt, text='Height:')
        width_label = ttk.Label(custom_prompt, text='Width:')
        bomb_amount_label = ttk.Label(custom_prompt, text='Mines:')

        width_input = ttk.Spinbox(custom_prompt, width=5, from_=9, to=24)
        height_input = ttk.Spinbox(custom_prompt, width=5, from_=9, to=30)
        bomb_amount_input = ttk.Spinbox(custom_prompt, width=5, from_=9, to=99)

        ok_button = ttk.Button(custom_prompt, text='OK', command=return_custom)
        cancel_button = ttk.Button(custom_prompt,
                                   text='Cancel',
                                   command=custom_prompt.destroy)

        #place them one by one inside the window (grid system will perform better here (because I don't need to calculate x and y lol))
        height_label.grid(row=0, column=0, padx=15, pady=(30, 0))
        width_label.grid(row=1, column=0, padx=15, pady=(5, 0))
        bomb_amount_label.grid(row=2, column=0, padx=15, pady=(5, 0))

        height_input.grid(row=0, column=1, padx=15, pady=(30, 0))
        width_input.grid(row=1, column=1, padx=15, pady=(5, 0))
        bomb_amount_input.grid(row=2, column=1, padx=15, pady=(5, 0))

        ok_button.grid(row=0, column=2, pady=(30, 0))
        cancel_button.grid(row=2, column=2, pady=(5, 0))

        #initialize the value in the input box to current value
        width_input.set(self.width)
        height_input.set(self.height)
        bomb_amount_input.set(self.total_mine)

        #show the window up
        custom_prompt.mainloop()
Exemple #2
0
    def show_record(self):
        #initialize the prompt window (I used a themed window so it looks better)
        record_win = ThemedTk(theme='breeze')
        record_win.title('Game Record')
        record_win.geometry('292x106')
        record_win.focus_force()

        beginner_label = Label(record_win, text='Beginner:')
        intermidiate_label = Label(record_win, text='Intermidiate:')
        expert_label = Label(record_win, text='Expert:')

        beginner_best = Label(record_win,
                              text='{} seconds'.format(self.record[0][0]))
        intermidiate_best = Label(record_win,
                                  text='{} seconds'.format(self.record[1][0]))
        expert_best = Label(record_win,
                            text='{} seconds'.format(self.record[2][0]))

        beginner_name = Label(record_win, text=self.record[0][1])
        intermidiate_name = Label(record_win, text=self.record[1][1])
        expert_name = Label(record_win, text=self.record[2][1])

        beginner_label.grid(row=0, column=0, padx=15, pady=(20, 0), sticky=W)
        intermidiate_label.grid(row=1, column=0, padx=15, sticky=W)
        expert_label.grid(row=2, column=0, padx=15, sticky=W)

        beginner_best.grid(row=0, column=1, pady=(20, 0), sticky=W)
        intermidiate_best.grid(row=1, column=1, sticky=W)
        expert_best.grid(row=2, column=1, sticky=W)

        beginner_name.grid(row=0,
                           column=2,
                           pady=(20, 0),
                           padx=(15, 0),
                           sticky=W)
        intermidiate_name.grid(row=1, column=2, padx=(15, 0), sticky=W)
        expert_name.grid(row=2, column=2, padx=(15, 0), sticky=W)

        record_win.update()

        record_win.mainloop()