0

How can this code be rewritten without the use of exec() if possible? I have tried finding a way myself but I am relatively new to coding and can't seem to figure it out.

def make_button(self, date, row, column):
    """
    Description:
        Build a date button.

    :param date: date.
    :type date: string

    :param row: row number.
    :type row: string

    :param column: column number.
    :type column: string
    """
    exec(
        "self.btn_" + date + " = ttk.Button(self.frame_days, text=" + date
        + ", width=5)\n"
        "self.btn_" + date + ".grid(row=" + row + " , column=" + column
        + ")\n"
        "self.btn_" + date + ".bind(\"<Button-1>\", self.get_date)"
    )

and

    def delete_buttons(self, date):
    """
    Description:
        Delete a date button.

    :param date: date.
    :type: string
    """
    exec(
        "self.btn_" + str(date) + ".destroy()"
    )
Latika Agarwal
  • 973
  • 1
  • 6
  • 11
protej
  • 1
  • 3

0 Answers0