我正在使用Tkinter制作带有GUI的程序。
程序收到CSV文件。然后是函数public static class MethodHolder{
private String property;
private Method getMethod;
private Method setMethod;
public MethodHolder() {
}
public MethodHolder(String property, Method getMethod, Method setMethod) {
this.property = property;
this.getMethod = getMethod;
this.setMethod = setMethod;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof MethodHolder)) return false;
MethodHolder that = (MethodHolder) o;
return Objects.equals(property, that.property);
}
@Override
public int hashCode() {
return Objects.hash(property);
}
}
Add
Delete
我已完成Update
部分,但我也可以完成add
部分,但不知何故,我只想尝试删除列。例如,条目是:
delete
我想仅通过2012-1221, Name Lastname,
我不能这样做。这是我的代码:
ID Number 2012-1221
请查看我的from Tkinter import *
import sys
import sys
import os
import operator
import datetime
import csv
import fileinput
root = Tk()
root.title("SCS Club/Guilds/Committee System")
root.grid()
root.geometry("400x450")
root.resizable(width=False, height=False)
files = StringVar()
label = Label(root, text="Clearance and Management", bg="white", fg="black")
label.pack(fill=X)
label1 = Label(root, text="Student Record", bg = "lightgreen", font = "chiller 20 bold").pack()
label2 = Label(root, text ="Enter file name:").pack()
fileName = Entry(root, textvariable=files, relief=GROOVE, bg="lightgreen").pack()
def fileOpen():
def newWindow():
def addData():
idGet = str(idno.get())
nameGet = str(nme.get())
courseGet = str(crse.get())
yearGet = str(yr.get())
fileNameGet = str(files.get())
with open(fileNameGet, 'ab') as csvfile:
writer = csv.writer(csvfile, delimiter=',', quotechar = '|')
completeFields = idGet + ',' + nameGet +','+ courseGet +','+ yearGet
writer.writerow([completeFields])
addEntry.delete(0,"end")
idEntry.delete(0,"end")
crseEntry.delete(0,"end")
newWin = Toplevel()
newWin.geometry("400x200")
newWin.resizable(width=False,height=False)
newWin.title("Add Student")
addId = Label(newWin, text="ID Number").grid(row=1, column=0)
idno = StringVar(None)
idEntry = Entry(newWin, textvariable=idno,bg="lightgreen")
idEntry.grid(row=1, column=1)
addNme = Label(newWin, text="Name").grid(row=2, column=0)
nme = StringVar(None)
addEntry = Entry(newWin, textvariable=nme, text="Name")
addEntry.grid(row=2, column=1)
addCrse = Label(newWin, text="course").grid(row=3, column=0)
crse = StringVar(None)
crseEntry = Entry(newWin, textvariable=crse, text="Course")
crseEntry.grid(row=3, column=1)
addYr = Label(newWin, text="Year").grid(row=4, column=0)
yr = StringVar(None)
yrEntry = Entry(newWin, textvariable=yr, text="Year")
yrEntry.grid(row=4, column=1)
addFinal = Button(newWin, text="ADD", command=addData, relief=GROOVE).grid(row=5, column=1)
def deleteWindow():
def deleteData():
getID = str(idno.get())
fileName = str(files.get())
f = open(fileName,"r")
lines = f.readlines()
f.close()
f = open(fileName,"w")
for line in lines:
if line!=getID+"\n":
f.write(line)
f.close()
idEntry.delete(0,"end")
msg = Label(deleteWin, text="Removed Successfully", font="fixedsys 12 bold").place(x=10,y=50)
deleteWin = Toplevel()
deleteWin.geometry("200x100")
deleteWin.resizable(width=False, height=False)
deleteWin.title("DELETE")
delete_id = Label(deleteWin, text="ID Number ").grid(row=0,column=0)
idno = StringVar(None)
idEntry = Entry(deleteWin, text=idno, bg="lightgreen")
idEntry.grid(row=0,column=1)
deleteFinal = Button(deleteWin, text="REMOVE", command=deleteData, relief=GROOVE).grid(row=4, column=1)
filename = str(files.get())
nfile = open(filename, 'a+')
display = Label(root, text="Opened file successfully", font = "fixedsys 12 bold").place(x=10,y=120)
studentList = Listbox(root, width=45, height=14, bg="lightgreen")
for line in nfile:
studentList.insert(END, line)
studentList.place(x=12, y=200)
nfile.close()
addStud = Button(root, text="Add Student", width = 12, height = 2, command=newWindow, relief=GROOVE).place(x=12,y=150)
deleteStud = Button(root, text="Remove Student", width = 12, height = 2,command=deleteWindow, relief=GROOVE).place(x=115,y=150)
updateStud = Button(root, text="Update", width = 9, height = 2,command=updateWindow, relief=GROOVE).place(x=215, y=150)
addFile = Button(root, text="Open File", width = 12, height = 2, command=fileOpen, relief=GROOVE).pack()
root.mainloop()
root.mainloop()
部分。我可以删除一个条目,但我必须拼出一切,对于用户来说这将是一件麻烦的事情吗?我希望通过delete
删除条目,以便更轻松。任何帮助表示赞赏。谢谢!