from tkinter import *
from api.moodle import MoodleAPI
from config import CONFIG
from tkhtmlview import HTMLLabel
def getIdAndName(course):
coursesId=[]
courseName=[]
for i in course:
coursesId.append(i.get("id"))
tmp=i.get("name").split(" ")
courseName.append(tmp[1])
return coursesId ,courseName
def createMoodleWin(moodle):
if moodle.status:
# ===== 取得課程ID與名稱 =====
c = moodle.getCourses("1092")
coursesId,coursesName=getIdAndName(c)
#for e in moodle.getUpcomingEvents()
win=Tk()
rightFrame=Frame(win,bg="red")
leftFrame=Frame(win)
#===== 右框 初始化 用html去印出所有資料=====
htmlLb=HTMLLabel(rightFrame,html="")
htmlScrollbar=Scrollbar(rightFrame)
htmlLb.configure(yscrollcommand=htmlScrollbar.set)
htmlScrollbar.pack(fill=Y,side=RIGHT)
htmlLb.pack()
leftFrame.pack(fill=BOTH,side=LEFT)
rightFrame.pack(fill=BOTH)
#=====Leftframe 1.button ->show UpComingEvent 2.choose courses=======
def showUpComingEvent(): #叫出未來事件
tmphtml=''''''
for e in moodle.getUpcomingEvents():
tmphtml+='''
{}
時間:{}
'''.format(e.get("name"),e.get("time") ) #tmphtml+='''''' htmlLb.set_html(tmphtml) upComingEventBtn=Button(leftFrame,text="未來事件",font="Helvetica 10",command= lambda:showUpComingEvent() ) coursesListBox=Listbox(leftFrame) mylb=Label(leftFrame,text="我的課程",font="Helvetica 15") coursesListBox.insert(END,*coursesName) mylb.pack(fill=X) coursesListBox.pack(fill=BOTH) upComingEventBtn.pack(fill=BOTH,pady=10) #=======rightframe ->show everything which I click====== def itemSelected(event): obj = event.widget Index = obj.curselection() tmpId=coursesId[coursesName.index(str(obj.get(Index)))] Html='''