簡體   English   中英

tkinter中輸入的Python Qrcode問題

[英]Python Qrcode problem with input in tkinter

我正在嘗試創建一個程序,它會詢問您一個鏈接,然后它會為您提供該鏈接的二維碼。 但我不能使用我要求的輸入,所以它只會創建一個沒有任何內容的 qrcode。

我需要幫助向用戶詢問輸入,然后使用該輸入將其轉換為 qrcode 我已經修復了我的打開按鈕我打開了。 以顯示。

import qrcode 
import tkinter
from PIL import Image



main = tkinter.Tk("Link converter to QrCode ")
main.title("Link converter to Qr Code")
main.geometry("685x85")


link = tkinter.Label(
    main, 
    width="30",
    text=('Link:'))
link.grid(row=0)


e1 = tkinter.Entry(
    main, 
    bd="5", 
    width="75",
    text=(""))
e1.grid(row=0, column=1)

qrcode.make(e1.get())
img = qrcode.make(e1.get())

button_create = tkinter.Button( 
    main, 
    text="Click to create the Qrcode.",  
    command = lambda:qrcode.make(e1.get()) and img.save("")  )
button_create.grid(row=2, column=1)




button_open = tkinter.Button ( 
    main,  
    text="Click here to open the Qrcode", 
    command = lambda: img.show(""), 
    width="25")
button_open.grid(row=2, column=0)


exit_button = tkinter.Button(
    main,
    width=("15"),
    text='Exit',
    command= lambda: main.quit())
exit_button.grid(row=4, column=0)



main.mainloop()

當你寫下這一行時:

img = qrcode.make(e1.get())

它會創建一個空的 qr,當您調用 img 時,它會返回這個空的 qr。 您必須在函數內執行 img 並使用按鈕調用它。 這是解決方案:

import qrcode 
import tkinter
from PIL import Image



main = tkinter.Tk("Link converter to QrCode ")
main.title("Link converter to Qr Code")
main.geometry("685x85")


link = tkinter.Label(
    main, 
    width="30",
    text=('Link:'))
link.grid(row=0)


e1 = tkinter.Entry(
    main, 
    bd="5", 
    width="75",
    text=(""))
e1.grid(row=0, column=1)

def makeqr():
    img = qrcode.make(e1.get())
    return img

button_create = tkinter.Button( 
    main, 
    text="Click to create the Qrcode.",  
    command = lambda:makeqr().save("")  )
button_create.grid(row=2, column=1)




button_open = tkinter.Button ( 
    main,  
    text="Click here to open the Qrcode", 
    command = lambda: makeqr().show(""), 
    width="25")
button_open.grid(row=2, column=0)


exit_button = tkinter.Button(
    main,
    width=("15"),
    text='Exit',
    command= lambda: main.quit())
exit_button.grid(row=4, column=0)



main.mainloop()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM