基本上下面是我现在所拥有的。问题是这些按钮中的每一个都会打开一个新窗口,我希望在右上角我有当前功能,例如显示添加课程,然后当我单击“添加时间”时,添加课程将被删除并添加时间显示。有没有一种方法可以为每个“编辑”dict 操作执行此操作,并且在此窗口的右下方还打印了一个“最新”表?谢谢。
class menu():
def __init__(self, master):
self.master = master
self.table = {}
self.createButtons()
# creates buttons with alignment and their functions
def createButtons(self):
load = Button(self.master, text = "Load Table",
command = self.loadTable)
load.grid(row =0, column =0, pady = 30)
course = Button(self.master, text = "Add Course",
command = self.addCourse)
course.grid(row =1, column =0, pady = 30)
time = Button(self.master, text = "Add Time",
command = self.addTime)
time.grid(row =2, column =0, pady = 30)
reset = Button(self.master, text = "Reset Time",
command = self.resetTime)
reset.grid(row =3, column =0, pady = 30)
comment = Button(self.master, text = "Change Comment",
command = self.changeComment)
comment.grid(row =4, column =0, pady = 30)
view = Button(self.master, text = "View Table",
command = self.viewTable)
view.grid(row =5, column =0, pady = 30)
def addCourse(self):
#creates addCourse window and text boxes for input
toplevel = Toplevel()
toplevel.title('Add Course')
Label (toplevel, text='Enter the course name').grid()
courseBox = Entry(toplevel, width=10)
courseBox.grid()
label =Label (toplevel, text='Enter the hours per week spent on course')
label.grid(padx=10,pady=10)
weekHoursBox = Entry(toplevel, width=10)
weekHoursBox.grid()
#function to accept input from boxes into dict
def callback():
course = courseBox.get()
weekHours = weekHoursBox.get()
string = "0 "+ str(weekHours) + " "
self.table[course] = string
enterB = Button(toplevel, text='Enter Information', command = callback)
enterB.grid(pady=10)