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與名稱 ===== 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(): #叫出未來事件 ht='''
讀取中
''' htmlLb.set_html(ht) win.update() 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") 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)))] ht='''

讀取中
''' htmlLb.set_html(ht) win.update() Html='''

本周作業

    ''' for work in moodle.getWeekWorkInCourse(str(tmpId)): Html+='''
  1. {}
  2. '''.format(work.get("link"),work.get("name") ) Html+='''

最新公告

    ''' for anno in moodle.getAnnoInCourse(str(tmpId)): Html+='''
  1. {}
  2. '''.format(anno.get("title")) Html+='''
''' htmlLb.set_html(Html) coursesName=[] coursesListBox.insert(END,*coursesName) win.update() coursesId,coursesName=getIdAndName(moodle.getCourses("1092")) coursesListBox.insert(END,*coursesName) print(coursesName) coursesListBox.bind("<>", itemSelected) win.mainloop() else: print("Moodle 登入失敗")