我在使用python时遇到问题,我正在尝试制作QRcode创建应用程序



>我在单击((函数中遇到问题,该函数必须在按下按钮时执行 我已经定义了变量,但它显示了"变量未定义"的错误消息

import tkinter as tk
import pyqrcode as qr
import png
from pyqrcode import QRCode
window = tk.Tk()
window.title("QR")
label = tk.Label(window,text="QR maker",font=("Helvetica",50)).pack()
label = tk.Label(window,text="Enter link",font=("Helvetica",10)).pack()
txt = tk.Entry(window,width=50).pack()
label = tk.Label(window,text="Enter size",font=("Helvetica",10)).pack()
txt2 = tk.Entry(window,width=10).pack()
label = tk.Label(window,text="enter name",font=("Helvetica",10)).pack()
txt3 = tk.Entry(window,width=50).pack()
def clicked():
Qstr = txt.get()
a = int(txt2.get())
b = txt3.get() 
url = qr.create(Qstr)
url.png(b,scale=a)
but = tk.Button(window,text="fill",command=fill).pack()
but2 = tk.Button(window,text="press here",command=clicked).pack()
window.geometry('1920x1080')
window.mainloop()

正如@acw1668所述,您需要将txt = tk.Entry(...).pack()分成两行。

这将是您的代码:

import tkinter as tk
import pyqrcode as qr
import png
from pyqrcode import QRCode
window = tk.Tk()
window.title("QR")
label = tk.Label(window,text="QR maker",font=("Helvetica",50))
label.pack()
label = tk.Label(window,text="Enter link",font=("Helvetica",10))
label.pack()
txt = tk.Entry(window,width=50)
txt.pack()
label = tk.Label(window,text="Enter size",font=("Helvetica",10))
label.pack()
txt2 = tk.Entry(window,width=10)
txt2.pack()
label = tk.Label(window,text="enter name",font=("Helvetica",10)).pack()
txt3 = tk.Entry(window,width=50)
txt3.pack()
def clicked():
Qstr = txt.get()
a = int(txt2.get())
b = txt3.get() 
url = qr.create(Qstr)
url.png(b,scale=a)
but = tk.Button(window,text="fill",command=fill)
but.pack()
but2 = tk.Button(window,text="press here",command=clicked)
but2.pack()
window.geometry('1920x1080')
window.mainloop()

希望这有帮助!

相关内容

  • 没有找到相关文章

最新更新