CDT-1D / char_screen.py
char_screen.py
Raw
from tkinter import *
from copy import deepcopy
from random import choice
from Characters import char_list
import initialise


# randomly pick 3 characters to be displayed as options
def random_char_generator():
    global a
    a = choice(temp_char_list)
    temp_char_list.remove(a)
    global b
    b = choice(temp_char_list)
    temp_char_list.remove(b)
    global c
    c = choice(temp_char_list)
    temp_char_list.remove(c)


# create a temp_list of data to remove elements so the original copy is not affected
def generate_temp_list():
    global temp_char_list
    temp_char_list = deepcopy(char_list)


def call_chara(root):
    # creating a frame (a canvas that is within the screen that stores the widgets)
    frame = Frame(root)
    frame.tk.call('tk', 'scaling', 2)
    frame.grid()

    generate_temp_list()
    random_char_generator()


    char_label = Label(frame, text="Choose your character!")
    char_label.grid(row=2, column=2)

    variable1 = a
    variable2 = b
    variable3 = c

    # checking the character to display its description
    def check_character(var):
        for char in initialise.char_desc_dict:
            if var == char:
                return initialise.char_desc_dict[char]

    # create buttons for characters
    char1 = Button(frame, text=f"{variable1} \n {check_character(variable1)} ", command=lambda: change_to_next(frame, variable1))
    char2 = Button(frame, text=f"{variable2} \n {check_character(variable2)}", command=lambda: change_to_next(frame, variable2))
    char3 = Button(frame, text=f"{variable3} \n {check_character(variable3)}", command=lambda: change_to_next(frame, variable3))

    # buttons positioning
    char1.grid(row=3, column=0)
    char2.grid(row=3, column=2)
    char3.grid(row=3, column=4)


    # change call value of this screen (Prevent repeat call here)
    initialise.call_value_dict["char"] = False



def change_to_next(frame, variable):
    # destroy current frame
    frame.grid_forget()

    # store what is clicked
    initialise.starting_char[0] = variable
    # change call value of next screen (Calls next screen)
    initialise.call_value_dict["topic"] = True
    # change update value of this screen (updates this)
    initialise.update_value_dict["char"] = True




def update_chara(stat):
    initialise.update_value_dict["char"] = False