大部分代码是由我的教授提供的,我必须更改他的格式。但是,当我运行程序时,他的原始代码甚至没有在 tk 框中提供任何内容。我做了一些改变,但没有什么是很有效的。有什么建议吗??
这是我的主要代码:
from Tkinter import *
import todo
master = Tk()
class todoApp():
def __init__(self, master):
self.master = master
self.frame = Frame(master)
self.frame.grid()
self.todo = todo.todoList()
self.saveButton = Button(self.frame, text="Save", command=self.save)
self.saveButton.grid()
self.restoreButton = Button(self.frame, text="Restore", command = self.restore)
self.restoreButton.grid(row=1, column=1)
self.addButton = Button(self.frame, text="Add", command=self.add)
self.addButton.grid(row=0,column=2)
self.doneButton = Button(self.frame, text="Done", command=self.done)
self.doneButton.grid(row=0,column=3)
self.button = Button(self.frame, text="Quit", command=self.quit)
self.button.grid(row=0, column=4)
label = Label(self.frame, text="New Task: ")
label.grid()
self.entry = Entry(self.frame)
self.entry.grid(row=1, column=1, columnspan=4)
frame1 = LabelFrame(self.frame, text="Tasks")
frame1.grid(columnspan=5, sticky=E+W)
frame1.columnconfigure(0,weight=1)
self.tasks = Listbox(frame1)
self.tasks.grid(sticky=E+W)
frame2 = LabelFrame(self.frame, text="Completed")
frame2.grid(columnspan=5, sticky=E+W)
frame2.columnconfigure(0,weight=1)
self.completed = Listbox(frame2)
self.completed.grid(sticky=E+W)
def save(self):
self.todo.saveList("tasks.txt")
def restore(self):
self.todo.restoreList("tasks.txt")
items = self.todo.getTasks()
self.tasks.delete(0,END)
for item in [ "study", "grocery shop", "cram for finals!", "sleep", "build a gingerbread house" ]:
self.tasks.insert(END,item)
items = self.todo.getCompleted()
self.completed.delete(0,END)
for item in items:
self.completed.insert(END,item)
def add(self):
task = self.entry.get()
self.todo.addTask(task)
self.tasks.insert(END,task)
def done(self):
selection = self.tasks.curselection()
if len(selection) == 0:
return
task = self.tasks.get(selection[0])
self.todo.completeTask(task)
self.tasks.delete(selction[0])
self.completed.insert(END,task)
def quit(self):
self.frame.quit()
self.master.destroy()
master.mainloop()
todo
进口是:
class todoList:
def __init__(self):
self.todo = []
self.done = []
def addTask(self,task):
self.todo.append(task)
def completeTask(self,task):
if self.todo.count(task) > 0:
self.todo.remove(task)
self.done.append(task)
def getTasks(self):
return self.todo
def getCompleted(self):
return self.done