1. 程式人生 > >python-生成二維碼圖片

python-生成二維碼圖片

from tkinter import * import qrcode

def jiemian_info(): ws = jiemian.winfo_screenwidth() hs = jiemian.winfo_screenheight() x = (ws / 2) - 200 y = (hs / 2) - 200 print("%d,%d" % (ws, hs)) return x, y jiemian = Tk() jiemian.title(“登入小助手”) a, b = jiemian_info() jiemian.geometry(“600x650+%d+%d” % (a, b)) Label(jiemian, text=“輸入:”).grid(row=0, column=0, stick=E,pady=10) ‘’‘設定文字框’’’ url = Entry(jiemian,font=(‘微軟雅黑’,10),width=40) #,width=40 url.grid(row=0, column=1, stick=E,pady=10,padx=5) label_img = Label(jiemian, text=“此處生成二維碼”) # ,image=button() ,image=path ,labelanchor=NW label_img.grid(row=2, column=1, stick=E+W,pady=10) #, ipady=20, ipadx=20 row=3, column=1 img,path,label=None,None,None def button(): global img, path, label img = qrcode.make(url.get()) img.save(“tupian.gif”) path=PhotoImage(file=‘tupian.gif’) label = Label(jiemian, image=path,width=340,height=340) #,width=340,height=340 label.grid(row=3, column=1, stick=E+W, pady=10, ipady=10, ipadx=10) ‘’‘設定按鈕’’’ Button(jiemian,text=“生成二維碼”,width=28,command=button).grid(row=1, column=1, stick=E+W,pady=10) # jiemian.mainloop()