我正在为驾校创建软件,但仅限于我可以使用哪些插件。我还必须为数据库使用文本文件,而不是能够使用SQL等。我似乎无法弄清楚下一阶段。 这是场景:
每位教师都有唯一的登录名,他们可以选择将课程预订到日历/时间表上,也可以只查看它。问题是我不确定如何在不创建大量文本文件的情况下存储数据,因为最初我的想法是每位讲师都可以查看自己的个人日历/时间表(通过其唯一的登录信息链接在一起)但是,由于日历的工作原理,每周需要使用自己的文本文件,然后将文本文件的数量乘以教师总数。 日历和时间表的代码是正确的(虽然工作并不完美,但是主要原理仍然存在):
import sys
import re
from tkinter import *
import tkinter.messagebox as box
import tkinter.font as Font
import time
import calendar
#from tkinter import font
from tkinter import ttk
def Calendar():
def mainTimetable():
#root1 = Tk()
#frame = Frame(root1)
days = ["","Mon","Tue","Wed","Thur","Fri","Sat","Sun"]
hours = ["","08:00","09:00","10:00","11:00","12:00","13:00","14:00","15:00",
"16:00","17:00","18:00"]
class WrappedButtons:
def __init__(self, master, **kwargs):
self.button = Button(master,font=('Courier'),fg='#333333',bg='#CCCCCC', **kwargs)
self.name = ''
def nameToggle(self):
if not self.name:
self.name = nameEntry.get()
else:
self.name = ''
self.button.config(text=self.name)
def subTimetable():
global nameEntry
popup = Toplevel()
#popup.title('Timetable')
for x in range(12):
Label(popup,font=('Courier'),fg='#333333',bg='#CCCCCC', text=hours[x]).grid(row=x,column=0)
for x in range(8):
Label(popup,font=('Courier'),fg='#333333',bg='#CCCCCC',text=days[x]).grid(row=0,column=x)
if x < 7: # this avoids an extra column of buttons
for y in range(11):
temp = WrappedButtons(popup,width=20)
temp.button.config(command=temp.nameToggle)
temp.button.grid(row=y+1,column=x+1)
Label(popup,text = "Enter the name of pupil and click the slot you wish to fill/remove: ")\
.grid(row=13,column=0,columnspan=4)
nameEntry = Entry(popup,width=40)
nameEntry.grid(row=13,column=4,columnspan=2)
backButton = Button(popup,font=('Courier'),fg='#333333',bg='#CCCCCC',text='Back',command= popup.destroy)#lambda: [f() for f in[popup.destroy,ownermenu]]).grid(row=13,column=6) # Add functionality to return to user page
submitButton = Button(popup,text='Submit Data').grid(row=13,column=7)
menubar = Menu(popup)
filemenu = Menu(menubar,tearoff=0)
filemenu.add_command(label='Home',command=lambda:[f() for f in [popup.destroy,home1]])
filemenu.add_separator()
filemenu.add_command(label='Exit',command=popup.destroy)
menubar.add_cascade(label='Page',menu=filemenu)
popup.config(menu=menubar)
popup.configure(bg='#333333')
#popup.overrideredirect(True)
#popup.geometry("{0}x{1}+0+0".format(popup.winfo_screenwidth(), popup.winfo_screenheight()))
subTimetable()
#root.mainloop()
root = Tk()
root.title('Calendar')
root.configure(bg='#333333')
permanentFrame,newFrame = Frame(root), Frame(root)
permanentFrame.pack(side='top')
newFrame.pack(side='top')
months = {1: 31, 2: 28, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31}
lbMonths = Label(permanentFrame,text='Months: ',fg='#333333',bg='#CCCCCC')
lbMonths.pack()
dropMonths = ttk.Combobox(permanentFrame, values=list(months.keys()))
dropMonths.pack()
class ButtonsWrap:
def __init__(self,master,month,day, **kwargs):
self.button = Button(master,**kwargs)
self.monthInd = month-1
self.dayInd = day-1
self.toplevel = False
self.thing = None
def popClose(self):
self.thing.destroy()
self.toplevel = False
self.thing = None
def popup(self):
if not self.toplevel:
self.thing = Toplevel()
self.toplevel = True
#Label(self.thing, command=mainTimetable).pack()
self.popClose
mainTimetable()
self.thing.protocol("WM_DELETE_WINDOW",self.popClose) #Add back in when 'back' functionality is complete
buttons = []
def makeCalendar(blank):
curMonth = int(dropMonths.get())
for i in buttons:
if i.thing:
i.thing.destroy()
for i in newFrame.slaves():
i.destroy()
rows = [Frame(newFrame) for i in range(5)]
[i.pack() for i in rows]
curDay = 1
for i in range(35):
if len(rows[0].slaves()) == 7:
rows.pop(0)
temp = ButtonsWrap(rows[0], curMonth,curDay,text='',height=1,width=2)
temp.button.pack(side='left')
buttons.append(temp)
if curDay <= months[curMonth]:
temp.button.config(text=curDay,command=temp.popup)
curDay += 1
dropMonths.bind('<<ComboboxSelected>>', makeCalendar)
menubar = Menu(root)
filemenu = Menu(menubar,tearoff=0)
filemenu.add_command(label='Home',command=lambda:[f() for f in [root.destroy,home1]])
filemenu.add_separator()
filemenu.add_command(label='Exit',command=root.destroy)
menubar.add_cascade(label='Page',menu=filemenu)
root.config(menu=menubar)
root.overrideredirect(True)
root.geometry("{0}x{1}+0+0".format(root.winfo_screenwidth(), root.winfo_screenheight()))
root.mainloop()
Calendar()
它的工作原理是允许教师键入时间表,然后我的目标是保存时间表,以便将来可以引用它(因此不会在每次关闭时重置)。达到目标的有效方法是什么?
如我所知,如果我对这个问题的解释不好,请随时提问。