您的位置:首页 > 其它

存档2

2016-08-12 16:21 176 查看
#!/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()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: