我试图创建一个程序,要求你一个链接,而不是它给你一个qrcode的链接。但是我不能使用我所要求的输入,所以它只是创建一个没有任何东西的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()发布于 2022-06-16 21:37:24
当你写这一行时:
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()https://stackoverflow.com/questions/72651935
复制相似问题