2017-07-18 57 views
-1

當我運行下面的代碼並且GUI打開時,並且當我在輸入框中輸入內容並按下按鈕時,它會顯示下面提到的錯誤。 但是,當我使用place而不是grid,它工作正常。 我也使用pyqr代碼庫。python網格不允許get()工作

有沒有辦法解決這個問題?

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

.grid()該方法在Tkinter的返回None。因此,當你做例如爲:

self.L1=Label(master, text="Enter the qr content").grid(row=0, column=1, columnspan =2) 

你分配到Noneself.L1。相反,你需要分爲兩行的Label(或EntryButton)的創建像這樣:

self.L1=Label(master, text="Enter the qr content") 
self.L1.grid(row=0, column=1, columnspan =2)