如果可能的话,如何在不使用exec()的情况下重写此代码?我自己也尝试过找一种方法,但我对编码比较陌生,似乎无法解决问题。
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)"
)
和
def delete_buttons(self, date):
"""
Description:
Delete a date button.
:param date: date.
:type: string
"""
exec(
"self.btn_" + str(date) + ".destroy()"
)