当我运行以下代码并打开GUI时,当我在输入框中输入内容并按下按钮时,它会显示下面提到的错误。
但是,当我使用place
代替grid
时,它可以正常工作。
我也在使用pyqr代码库。
有没有解决这个问题?
import tkinter
import pyqrcode
from multiprocessing import Process, Queue
from pyqrcode import *
from tkinter import *
from tkinter import messagebox
from tkinter import Tk, Label, Button, Entry
class app:
def __init__(self, master):
self.master = master
master.title("Prosmack qr")
self.L1=Label(master, text="Enter the qr content").grid(row=0, column=1, columnspan =2)
self.E1=Entry(master, text="Enter the qr content").grid(row=0,column=3)
self.B1=Button(master, text="Save as SVG" ,command = self.message1).grid(row=1, column=1, columnspan =2)
self.B2=Button(master, text="Save as EPS" ,command = self.message2).grid(row=1, column=3, columnspan =2)
self.L2=Label(master,text="Copyrights owned by prosmack").grid(row=2, column=1,columnspan=5)
def message1(self):
url = pyqrcode.create(self.E1.get())
print(url.terminal(quiet_zone=1))
url.svg('uca-url.svg', scale=1)
def message2(self):
url = pyqrcode.create(self.E1.get())
print(url.terminal(quiet_zone=1))
url.eps('uca-url.eps', scale=2)
root = Tk()
app = app(root)
root.resizable(0,0)
root.mainloop
这是终端中显示的错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Home\AppData\Local\Programs\Python\Python36-32\lib\idlelib\run.py", line 137, in main
seq, request = rpc.request_queue.get(block=True, timeout=0.05)
File "C:\Users\Home\AppData\Local\Programs\Python\Python36-32\lib\queue.py", line 172, in get
raise Empty
queue.Empty
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Home\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "C:\Users\Home\Documents\New folder\fk.py", line 18, in message1
url = pyqrcode.create(self.E1.get())
AttributeError: 'NoneType' object has no attribute 'get'
答案 0 :(得分:0)
.grid()
方法在Tkinter中返回None
。因此,当你这样做时:
self.L1=Label(master, text="Enter the qr content").grid(row=0, column=1, columnspan =2)
您已将None
分配给self.L1
。相反,您需要将Label
(或Entry
或Button
)的创建分为两行,如下所示:
self.L1=Label(master, text="Enter the qr content")
self.L1.grid(row=0, column=1, columnspan =2)