diff --git a/Lottery interface b/Lottery interface new file mode 100644 index 0000000..05beebe --- /dev/null +++ b/Lottery interface @@ -0,0 +1,132 @@ +#图像界面程序 +#12个备选选项,2个功能按钮 +#点击开始,不断旋转,点暂停,停止 +#-*- coding:utf-8 -*- +import tkinter +import threading +import time + +#生成主窗口,窗口标题,大小 +root = tkinter.Tk() +#1.1窗口的标题 +root.title('抽奖界面') +#1.2窗口的大小 +root.minsize(300,300) +#2摆放按钮 按钮的位置大小 +btn1 = tkinter.Button(root,text='一等奖',bg='red') +btn1.place(x=20,y=20,width=50,height=50) + +btn2 = tkinter.Button(root,text='二等奖',bg='white') +btn2.place(x=90,y=20,width=50,height=50) + +btn3 = tkinter.Button(root,text='三等奖',bg='white') +btn3.place(x=160,y=20,width=50,height=50) + +btn4 = tkinter.Button(root,text='四等奖',bg='white') +btn4.place(x=230,y=20,width=50,height=50) + +btn5 = tkinter.Button(root,text='五等奖',bg='white') +btn5.place(x=230,y=90,width=50,height=50) + +btn6 = tkinter.Button(root,text='六等奖',bg='white') +btn6.place(x=230,y=160,width=50,height=50) + +btn7 = tkinter.Button(root,text='七等奖',bg='white') +btn7.place(x=230,y=230,width=50,height=50) + +btn8 = tkinter.Button(root,text='八等奖',bg='white') +btn8.place(x=160,y=230,width=50,height=50) + +btn9 = tkinter.Button(root,text='优秀奖',bg='white') +btn9.place(x=90,y=230,width=50,height=50) + +btn10 = tkinter.Button(root,text='优秀奖',bg='white') +btn10.place(x=20,y=230,width=50,height=50) + +btn11 = tkinter.Button(root,text='优秀奖',bg='white') +btn11.place(x=20,y=160,width=50,height=50) + +btn12 = tkinter.Button(root,text='优秀奖',bg='white') +btn12.place(x=20,y=90,width=50,height=50) + +#2.1将所有选项添加到列表中 +list = [btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9,btn10,btn11,btn12] + +#2.2定义是否开启循环标志 +isloop = False + +#2.3定义是否停止标志 +stopsign = False +#停止ID目的:通过id的索引来确定对应的选项 +stopid = None + +#定义一个函数:目的:1通过函数循环备选选项 2设置选项背景颜色(选中为红,未选中为白) +def round(): + #global声明变量的作用域为全局作用域 + global isloop + global stopid + #判断是否开始循环 + if isloop == True: + return + i = 1 + #isinstance()判断对象是否是一个一直类型 + #isinstance(object,classinfo) object实例对象 classinfo直接或间接地类名,基本数据类型 + if isinstance(stopid,int): + i = stopid + #3.1开始循环 + while True: + #延时操作 + time.sleep(0.03) + #3.2将所有的组件背景变为白色 + for x in list: + x['bg'] = 'white' + #3.3将当前数值对应的组件变为红色 + list[i]['bg'] = 'red' + + i+= 1 + print('当前的i为:',i) + + #如果i大于最大索引值i为0 + if i >=len(list): + i = 0 + if stopsign == True: + isloop = False + stopid = i + break +#4定义停止方法 +def stop1(): + global stopsign + + if stopsign ==True: + return + stopsign = True +#5定义开始的方法 +def newtask(): + global isloop + global stopsign + + stopsign = False + #建立线程 + #Thread是线程类,第一种方法直接传入,第二种继承并覆盖run() + #global线程组None + #target要执行的方法 + #name线程名 + #args/kwargs:要传入方法的参数 + t= threading.Thread(target=round) + #开启线程 + t.start() + isloop = True + +#6设置开始按钮 +btn_start = tkinter.Button(root,text='开始',command=newtask) +btn_start.place(x=90,y=125,width=50,height=50) +#7设置停止按钮 +btn_stop = tkinter.Button(root,text='停止',command=stop1) +btn_stop.place(x=160,y=125,width=50,height=50) + +root.mainloop() + + + + + diff --git a/PdfToWord b/PdfToWord new file mode 100644 index 0000000..cc0d5a6 --- /dev/null +++ b/PdfToWord @@ -0,0 +1,59 @@ +from pdfminer.pdfparser import PDFParser,PDFDocument +from pdfminer.pdfinterp import PDFResourceManager,PDFPageInterpreter +from pdfminer.layout import LAParams +from pdfminer.converter import PDFPageAggregator +from pdfminer.pdfinterp import PDFTextExtractionNotAllowed +from docx import Document + +document = Document() + + +def parse(): + # rb以二进制读模式打开本地pdf文件 + fn = open('&&&&&&&&&&&&&&&&&&&.pdf', 'rb') + # 创建一个pdf文档分析器 + parser = PDFParser(fn) + # 创建一个PDF文档 + doc = PDFDocument() + # 连接分析器 与文档对象 + parser.set_document(doc) + doc.set_parser(parser) + + # 提供初始化密码doc.initialize("lianxipython") + # 如果没有密码 就创建一个空的字符串 + doc.initialize("") + # 检测文档是否提供txt转换,不提供就忽略 + if not doc.is_extractable: + raise PDFTextExtractionNotAllowed + + else: + # 创建PDf资源管理器 + resource = PDFResourceManager() + # 创建一个PDF参数分析器 + laparams = LAParams() + # 创建聚合器,用于读取文档的对象 + device = PDFPageAggregator(resource, laparams=laparams) + # 创建解释器,对文档编码,解释成Python能够识别的格式 + interpreter = PDFPageInterpreter(resource, device) + # 循环遍历列表,每次处理一页的内容 + # doc.get_pages() 获取page列表 + for page in doc.get_pages(): + # 利用解释器的process_page()方法解析读取单独页数 + interpreter.process_page(page) + # 使用聚合器get_result()方法获取内容 + layout = device.get_result() + # 这里layout是一个LTPage对象,里面存放着这个page解析出的各种对象 + for out in layout: + # 判断是否含有get_text()方法,获取我们想要的文字 + if hasattr(out, "get_text"): + # print(out.get_text(), type(out.get_text())) + content = out.get_text().replace(u'\xa0', u' ') # 将'\xa0'替换成u' '空格,这个\xa0就是&nbps空格 + #with open('test.txt','a') as f: + # f.write(out.get_text().replace(u'\xa0', u' ')+'\n') + document.add_paragraph( + content, style='ListBullet' # 添加段落,样式为unordered list类型 + ) + document.save('demo1.docx') # 保存这个文档 + +if __name__ == '__main__': + parse()