python簽名設計

來源:互聯網
上載者:User

標籤:開啟   怎麼   提示   python   box   標題   移動   入參   star   

將一個簽名網站http://www.uustv.com/的內容爬下來顯示出來

代碼:sign.py

from tkinter import *from tkinter import messageboximport requestsimport refrom PIL import Image,ImageTk#類比瀏覽器發送請求def download():    startUrl = ‘http://www.uustv.com/‘    name = enter.get()    #name = name.strip()    if not name:        messagebox.showinfo(‘提示:‘,‘請輸入使用者名稱‘)    else:        data= {            ‘word‘:name,            ‘sizes‘:60,            ‘fonts‘:‘jfcs.ttf‘,            ‘fontcolor‘:‘#000000‘        }        result = requests.post(startUrl,data = data)        result.encoding = ‘utf-8‘        html = result.text        reg =‘<div class="tu">.*?<img src="(.*?)"/></div>‘        imagePath = re.findall(reg,html)        #圖片完整路徑        imgUrl = startUrl + imagePath[0]       #擷取圖片內容        response = requests.get(imgUrl).content        f = open(‘{}.gif‘.format(name),‘wb‘)        f.write(response)        #寫入        #怎麼把圖片放到視窗上,顯示圖片        bm = ImageTk.PhotoImage(file =‘{}.gif‘.format(name))        label2 = Label(root,image = bm)        #image屬性        label2.bm = bm        #繪圖        label2.grid(row = 2,columnspan = 2)#建立視窗root = Tk()#標題root.title(‘簽名設計‘)#視窗大小,中間的是小寫x,而不 是乘號root.geometry(‘600x300‘)#視窗的初始位置root.geometry(‘+400+300‘)#標籤的控制項label = Label(root,text = ‘簽名‘,font = (‘華文行楷‘,20),fg = ‘red‘)#grid pack placelabel.grid()#輸入框enter = Entry(root,font = (‘微軟雅黑‘,20))#設定輸入框的位置enter.grid(row = 0,column = 1)#點擊按鈕button = Button(root,text = ‘設計簽名‘,font =(‘微軟雅黑‘,20),command = download) #調用函數#設定點擊按鈕的位置button.grid(row = 1,column = 0)#訊息迴圈,可以理解為顯示視窗root.mainloop()
View Code

關於圖形介面GUI的操作之前部落格已經說過了,主要就是三步:

1、root = Tk()

2、將標籤和按鈕等組件放進去

3、root.mainloop()

 

這裡用的是requests去請求一個網頁,post傳入參數網址和data,data是怎麼擷取的呢?

開啟瀏覽器,輸入網址然後右鍵檢查元素,點擊網路,重新整理頁面刪掉之前的記錄,然後輸入名字點擊擷取簽名

然後得到頁面如下:

注意右邊的參數即是我們需要的data,但是輸入的名字一直是變得,其餘三個是不會變的。

 

然後將py檔案轉換成window上執行的exe檔案

需要下載pyinstaller 和pywin32-221.win-amd64-py3.6 ,其中py3.6指的是python版本是3.6,amd64指的是64位,具體的視情況而定 。

https://sourceforge.net/projects/pywin32/files/pywin32/Build%20220/pywin32-221.win-amd64-py3.6.exe/download

下載安裝後,在sign.py檔案所在目錄中執行pyinstaller -F sign.py 。

會在目前的目錄下產生類似如下的一個目錄結構:

在dist目錄中存在新產生的exe檔案,可以點擊執行,移動到別的目錄一樣可以執行 。

 

效果如下:

 

python簽名設計

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.