Example #1
0
 def __init__(self, master, tower, click_command, *args, **kwarg):
     super().__init__(master)
     self._master = master
     self._tower = tower
     # set up the canvas, with 250 width and 40 height
     self._canvas = tk.Canvas(self,
                              width=250,
                              height=40,
                              bg="#4a2f48",
                              highlightthickness=0)
     self._canvas.pack(expand=True, fill=tk.BOTH)
     # create the label which display the tower name
     self._tower_label = Label(self._canvas,
                               text=tower.name,
                               fg="white",
                               bg="#4a2f48")
     self._tower_label.pack()
     # create the label which display the coin cost
     self._canvas.create_window(130, 10, window=self._tower_label)
     self._tower_coin = Label(self._canvas,
                              text=str(tower.base_cost) + " coins",
                              fg="white",
                              bg="#4a2f48")
     self._tower_coin.pack()
     # create the tower graph
     self._canvas.create_window(130, 30, window=self._tower_coin)
     tower.position = (tower.cell_size // 2, tower.cell_size // 2
                       )  # Position in centre
     tower.rotation = 3 * math.pi / 2  # Point up
     TowerView.draw(self._canvas, tower)
     # set up the click function for name, coin, other place to left click function
     select_tower = [self._canvas, self._tower_label, self._tower_coin]
     for i in select_tower:
         i.bind("<Button-1>", lambda event: click_command())
Example #2
0
    def __init__(self, master, tower, click_command, **kwargs):#, *args, **kwargs):
        '''
        Constructs an individual shop tower view including the tower on display
        and the command to execute upon clicked.
    
        tower (AbstractTower): the tower to display on the frame
        click_command: the command to run when the shop
            view is clicked on
        
        **kwargs: additional positional arguments
        '''
        super().__init__(master, **kwargs)
        self.configure(pady=10)

        self._tower = tower

        tower.position = (tower.cell_size//2, tower.cell_size//2)  #Position in centre
        tower.rotation = 3 * math.pi / 2  #Point up

        self._canvas = tk.Canvas(self, width=tower.cell_size, height=tower.cell_size,
            bg="#ff6600", bd=0, highlightthickness=0)
        self._canvas.pack(expand=True, side=tk.LEFT)

        TowerView.draw(self._canvas, tower)

        self._label = tk.Label(self, bg="#ff6600")
        self._label.configure(text="%s\nprice:%s" %(tower.name, tower.get_value()))
        self._label.pack(expand=True, side=tk.RIGHT)

        self.bind("<Button-1>", lambda event:click_command())
        self._canvas.bind("<Button-1>", lambda event:click_command())
        self._label.bind("<Button-1>", lambda event: click_command())
Example #3
0
    def __init__(self, master, tower, click_command, *args, **kwargs):
        super().__init__(master, *args, **kwargs)

        self.bind("<Button-1>", self.choose_tower)

        # The frame for price and name of a tower
        self._bind = tk.Frame(self, bg='#4B2E49')
        self._bind.pack(side=tk.LEFT, expand=1, fill=tk.X)
        self._bind.bind("<Button-1>", self.choose_tower)

        # setup canvas
        self._canvas = tk.Canvas(self._bind,
                                 bg='#4B2E49',
                                 highlightthickness=0,
                                 width=30,
                                 height=30)
        self._canvas.pack(side=tk.LEFT)
        self._canvas.bind("<Button-1>", self.choose_tower)

        # draw tower
        # Position in centre
        tower.position = (tower.cell_size // 2, tower.cell_size // 2)
        tower.rotation = 3 * math.pi / 2  # Point up
        TowerView.draw(self._canvas, tower)
        self.click_command = click_command

        # draw tower name
        self._tower_name = tk.Label(self._bind,
                                    text="{0}".format(tower.name),
                                    bg='#4B2E49',
                                    fg="white")
        self._tower_name.pack(side=tk.TOP, padx=40, expand=1, fill=tk.X)
        self._tower_name.bind("<Button-1>", self.choose_tower)

        self._tower = tower
        # draw tower price
        self._tower_price = tk.Label(self._bind,
                                     text="{0} coins".format(
                                         tower.get_value()),
                                     bg='#4B2E49',
                                     fg="white")
        self._tower_price.pack(side=tk.TOP, padx=40)
        self._tower_price.bind("<Button-1>", self.choose_tower)

        # Set Enter and leave for each widget.
        self._tower_name.bind("<Enter>", self.change_active)
        self._tower_name.bind("<Leave>", self.change_inactive)
        self._tower_price.bind("<Enter>", self.change_active)
        self._tower_price.bind("<Leave>", self.change_inactive)
        self._canvas.bind("<Enter>", self.change_active)
        self._canvas.bind("<Leave>", self.change_inactive)
        self._bind.bind("<Enter>", self.change_active)
        self._bind.bind("<Leave>", self.change_inactive)
Example #4
0
    def __init__(self, master, tower, *args, click_command, **kwargs):
        super().__init__(master, *args, **kwargs)
        """Inflict damage on the enemy

        Parameters:
            master (Tk): The window in which it appears
            tower: The tower for which information is displayed
            click_command: Allows selection from tower class
        """

        # Variables for setting dimension canvas inside Status Bar
        self._canvasHeight = 50
        self._canvasWidth = 100

        # Initilaise variables
        self._available_flag = None
        self._click_command = click_command

        #Create canvas
        self._canvas = tk.Canvas(master,
                                 bg=BACKGROUND_COLOUR,
                                 highlightbackground=BACKGROUND_COLOUR,
                                 width=self._canvasWidth,
                                 height=self._canvasHeight)
        self._canvas.pack(side=tk.TOP, fill=tk.BOTH, padx=20)

        #Draw tower in canvas
        tower.position = (tower.cell_size // 2, tower.cell_size // 2
                          )  # Position in centre
        tower.rotation = 3 * math.pi / 2  # Point up
        TowerView.draw(self._canvas, tower)

        #Create label fre tower name and value
        self._tower_label1 = tk.Label(self._canvas,
                                      text="{}".format(tower.name),
                                      bg=BACKGROUND_COLOUR,
                                      font=("Comic Sans", 8),
                                      fg="white")
        self._tower_label1.pack()
        self._tower_label2 = tk.Label(self._canvas,
                                      text="{} coins".format(
                                          tower.get_value()),
                                      bg=BACKGROUND_COLOUR,
                                      font=("Comic Sans", 8),
                                      fg="white")
        self._tower_label2.pack()

        #Bind mouse events to canvas.
        self._canvas.bind('<Button-1>', self._left_click)
        self._tower_label1.bind('<Button-1>', self._left_click)
        self._tower_label2.bind('<Button-1>', self._left_click)
Example #5
0
    def __init__(self, master, tower, click_command):
        """
        master: The Tkinter parent widget
        tower: The tower to display (an instance of AbstractTower)
        click_command: A callback function to be called when the tower
        is clicked.
        *args & **kwargs: Positional & keyword arguments to be passed
        to the tk.Frame constructor
        """

        super().__init__(master, bg = "light blue")

        self._master = master
        
        self._tower = tower

        self._click_command = click_command

        self._shop_frame = tk.Frame(self, bg = "light blue")
        self._shop_frame.pack(side = tk.TOP, expand = True, fill = tk.BOTH)
        self._shop_frame.bind("<Button-1>", self._click_command)
        self._shop_frame.bind("<Motion>", self.hover)
        self._shop_frame.bind("<Leave>", self.leave)
        
        self._image_canvas = tk.Canvas(self._shop_frame, height=30, width = 30,
                                       bg = "light blue", 
                                       highlightthickness=0)
        self._tower.position = (self._tower.cell_size // 2,
                                    self._tower.cell_size // 2) #In centre
        self._tower.rotation = 3 * math.pi / 2 #Point up
        TowerView.draw(self._image_canvas, self._tower)
        self._image_canvas.pack(side = tk.LEFT, anchor = tk.W, fill = tk.X)
        self._image_canvas.bind("<Button-1>", self._click_command)
        self._image_canvas.bind("<Motion>", self.hover)
        self._image_canvas.bind("<Leave>", self.leave)

        self._tower_label = tk.Label(self._shop_frame, text = self._tower.name
                                     + ": " + str(self._tower.base_cost)
                                     + " coins",
                                     bg = "light blue", fg = "black")
        self._tower_label.pack(side = tk.LEFT)
        self._tower_label.bind("<Button-1>", self._click_command)
        self._tower_label.bind("<Motion>", self.hover)
        self._tower_label.bind("<Leave>", self.leave)
Example #6
0
File: a3.py Project: mj221/CSSE1001
    def __init__(self, master, tower, click_command, *args, **kwargs):
        """Construct a shop bar for tower in a root window

        Parameters:
            master (tk.Tk): Frame to place the shop into
        """
        self._master = master
        super().__init__(master, bg = 'purple')
        tower.position = (tower.cell_size // 1, tower.cell_size // 1)  # Position in centre
        tower.rotation = 3 * math.pi / 2  # Point up
        self._canvas = w = tk.Canvas(self, bg = 'purple', bd=3, height = 55)
        w.pack(fill=tk.X)
        TowerView.draw(w, tower)
        self.item = w.create_text(180,30,fill = 'white',font = "Times 15 italic bold",
                                 text=tower.name +"\n{}".format(tower.get_value()))
        
        def click(event):
            """call back function for when a tower is clicked from the canvas
            """
            return click_command()
            

        w.bind("<Button-1>", click)
Example #7
0
    def __init__(self, master, tower, bg, highlight, click_command, *args, **kwargs):
        """Constructs a shop entry in a root frame

        Parameters:
            master (tk.Frame): Frame to place into
            ...
        """
        self._highlight = highlight
        self._background = bg
        self._available = False

        super().__init__(master, bg=bg, *args, **kwargs)

        self._canvas = tk.Canvas(self, bg=bg, width=tower.cell_size, height=tower.cell_size, highlightthickness=0)
        self._canvas.pack(side=tk.LEFT)

        tower.position = (tower.cell_size // 2, tower.cell_size // 2)  # Position in centre
        tower.rotation = 3 * math.pi / 2  # Point up
        TowerView.draw(self._canvas, tower)

        self._tower_name = tower.name
        self._tower_cost = str(tower.base_cost)
        self._tower_name_label = tk.Label(self, text=self._tower_name, bg=bg, fg="white", font=("TkDefaultFont", 12, "bold"))
        self._tower_name_label.pack()
        self._tower_cost_label = tk.Label(self, text=self._tower_cost + " coins", bg=bg, fg="white", font=("TkDefaultFont", 12, "normal"))
        self._tower_cost_label.pack()

        # change background colour when hovering cursor over
        self.bind("<Enter>", self.mouse_enter)
        self.bind("<Leave>", self.mouse_leave)

        # bind left clicking
        self.bind("<Button-1>", lambda event: click_command())
        self._tower_name_label.bind("<Button-1>", lambda event: click_command())
        self._tower_cost_label.bind("<Button-1>", lambda event: click_command())
        self._canvas.bind("<Button-1>", lambda event: click_command())