#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode Tkinter tutorial In this script, we use the Label widget to show an image. Author: Jan Bodnar Last modified: November 2015 Website: www.zetcode.com """ from PIL import Image, ImageTk from Tkinter import * from spider import spider class Example(Frame): def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent self.spider=spider() self.initUI() def initUI(self): self.parent.title("成績獲取小助手") self.img = self.spider.getCaptcha() img_captcha = ImageTk.PhotoImage(self.img) self.Lbl_captcha = Label(self, image=img_captcha) self.Lbl_captcha.image = img_captcha self.Btn_fresh=Button(self, text="刷新") self.Lbl_studentID=Label(self, text="學號") self.Lbl_password= Label(self, text="密碼") self.Lbl_verifyCode=Label(self, text="驗證碼") self.Btn_login=Button(self,text="登陸") self.Ety_studentID = Entry(self) self.Ety_password = Entry(self) self.Ety_verifyCode= Entry(self) self.Lbl_studentID.grid(row=0,column=0) self.Ety_studentID.grid(row=0,column=1) self.Lbl_password.grid(row=1,column=0) self.Ety_password.grid(row=1,column=1) self.Lbl_verifyCode.grid(row=2,column=0) self.Ety_verifyCode.grid(row=2,column=1) self.Lbl_captcha.grid(row=2,column=2) self.Btn_fresh.grid(row=3,column=2) self.Btn_login.grid(row=3,column=1) self.Btn_login.bind("<Button-1>", self.loginSystem) self.Btn_fresh.bind("<Button-1>", self.freshCaptcha) self.pack() def loginSystem(self,event): self.spider.studentID=self.Ety_studentID.get() self.spider.password=self.Ety_password.get() self.spider.captcha=self.Ety_verifyCode.get() self.spider.loginMainPage() result=self.spider.getAndSaveScore() if(result==0): self.show_toplevel('獲取失敗,請重試!') else: self.show_toplevel('獲取成功!') self.update() def show_toplevel(self,msg): self.top = Toplevel() self.top.title('操做提示') self.top.geometry("30x20+350+350") Label(self.top, text=msg).pack() def freshCaptcha(self,event): self.img = self.spider.getCaptcha() img_captcha = ImageTk.PhotoImage(self.img) self.Lbl_captcha = Label(self, image=img_captcha) self.Lbl_captcha.image = img_captcha self.Lbl_captcha.grid(row=2,column=2) self.update() def setGeometry(self): #w, h = self.img.size self.parent.geometry("300x150+300+300" ) def main(): root = Tk() ex = Example(root) ex.setGeometry() root.mainloop() if __name__ == '__main__': main()