2017-09-04 20 views
-1

これは私のコードです。このコードを実行しようとしているとき。私は次のエラーに直面する。誰でも私にそのエラーを修正する方法を教えてもらえます。このスクリプトは正常に実行できます。PythonでSQLite3でエラーが発生する

from tkinter import * 
import sqlite3 

global a, b 

def sair_mestre(): 
    global mestre 
    mestre.quit() 

def criar_tabela(): 
    c.execute("CREATE TABLE IF NOT EXISTS Registro (Nome text, Senha text)") 

def receberl(): 
    global Nome, Senha 
    Nome = entradalogin.get() 
    Senha = entradasenha.get() 
    ler_dados(Senha) 
    if x: 
     sucesso = Label(mestre, text="Login Realizado com sucesso!") 
     sucesso.grid(row=1,column=1) 
    else: 
     inexistente = Label(mestre, text="Login errado") 
     inexistente.grid(row=1, column=1) 

def receber2(): 
    logincadastro2 = entradalogin2.get() 
    senhacadastro2 = entradasenha2.get() 
    c.execute("INSERT INTO Registro VALUES(?, ?)", (logincadastro2, senhacadastro2)) # Utilização de Variáveis 
    conexao.commit() 
    cadastro.destroy() 

    realizado = Label(mestre, text="Cadastrado com sucesso") 
    realizado.grid(row=1, column=1) 

    botaorealizado = Button(mestre, text="Ok", command=sair_mestre) 
    botaorealizado.grid(row=2, column=1) 

def registro(): 
    programa.destroy() 

    global cadastro 
    cadastro = Frame(mestre) 
    cadastro.grid() 

    realizando_cadastro = Label(cadastro, text="Realizando Cadastro...") 
    realizando_cadastro.grid(row=0, column=1) 

    labellogin = Label(cadastro, text="Login") 
    labellogin.grid(row=1, column=0) 

    labelsenha = Label(cadastro, text="Senha") 
    labelsenha.grid(row=2, column=0) 

    global entradalogin2 
    entradalogin2 = Entry(cadastro) 
    entradalogin2.grid(row=1, column=1) 

    global entradasenha2 
    entradasenha2 = Entry(cadastro, show="•") 
    entradasenha2.grid(row=2, column=1) 

    botaocadastro = Button(cadastro, text="Ok", command=receber2) 
    botaocadastro.grid(row=3, column=1) 

def ler_dados (valorbusca): 
    global row 
    global x 
    buscar_dados = "SELECT * FROM Registro WHERE Nome = ? AND Senha = ?" 
    for row in c.execute(buscar_dados, (valorbusca,)): 
     if Nome and Senha in row: 
      x = True 


conexao = sqlite3.connect("Registro_Cadastro.db") 
c = conexao.cursor() 

criar_tabela() 

mestre = Tk() 

programa = Frame(mestre) 
programa.grid() 

login = Label(programa, text="Login") 
login.grid(row=0, column=0) 

global entradalogin 
entradalogin = Entry(programa) 
entradalogin.grid(row=0, column=1) 

senha = Label(programa, text="Senha") 
senha.grid(row=1, column=0) 

global entradasenha 
entradasenha = Entry(programa, show="•") 
entradasenha.grid(row=1, column=1) 

botaook = Button(programa, text="Entrar",command= receberl) 
botaook.grid(row=2, column=1) 

botaoregistro = Button(programa, text="Cadastro",command= registro) 
botaoregistro.grid(row=3,column=1) 

mestre.mainloop() 

これは私のプログラムによってスローされたエラーです。誰も私がこのエラーを解決するのを助けることができますか? エラーはreceberlにあると思います。あなたが機能receberller_dados(Senha)を呼び出すと、

buscar_dados = "SELECT * FROM Registro WHERE Nome = ? AND Senha = ?" 

Nomeが欠落しているように見えます:

File "-------", line 1558, in __call__ 
    return self.func(*args) 

File "------", line 17, in receberl 
    ler_dados(Senha) 

File "------", line 69, in ler_dados 
    for row in c.execute(buscar_dados, (valorbusca,)): 
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 2, and there are 1 supplied. 

答えて

2

あなたはこのクエリの2つの引数を提供する必要があります。あなたのSELECTクエリは、2つのパラメータをバインドしますが、あなた:あなたが取得しているエラーメッセージがかなり明確である

def ler_dados (nome, senha): 
    global row 
    global x 
    buscar_dados = "SELECT * FROM Registro WHERE Nome = ? AND Senha = ?" 
    for row in c.execute(buscar_dados, (nome, senha)): 
     if Nome and Senha in row: 
      x = True 
+0

は私が作った**を両方の変更を提案** Tkinterコールバックで例外が発生しました。 トレースバック(最新の最後の呼び出し): ファイル "-----"、1558行目、__call__内 return self.func(* args) ファイル " --- "、行16、receberl Nome = entradalogin.get()ファイル "-----"、2530行目get return self.tk.call(self._w、 'get') _tkinter.TclError:無効なコマンド名 ".5288976.5207312" –

+0

どのようなエラーが表示されますか? – PRMoureu

3

次のようなものを使用する必要がありますler_dados(Nome, Senha)最初

をし、その後にメソッドler_dadosを変更しますコードはそのうちの1つだけを指定します。

def receberl(): 
    global Nome, Senha 
    Nome = entradalogin.get() 
    Senha = entradasenha.get() 
    ler_dados(Nome, Senha) 
    # ... etc. 

そしてクエリバインドの両方のユーザー名とパスワード:修正するには、最初にユーザー名とパスワードの両方に合格するler_dados()にお電話を変更

def ler_dados(username, valorbusca): 
    global row 
    global x 
    buscar_dados = "SELECT * FROM Registro WHERE Nome = ? AND Senha = ?" 
    for row in c.execute(buscar_dados, (username, valorbusca,)): 
     if Nome and Senha in row: 
      x = True 
+0

Tkinterコールバックでの例外トレースバック(直近の最後のコール):ファイル "-----"、1558行目、コールreturn self.func(* args)File "-----" (self._w、 'get')_tkinter.TclError:--- 16行目、受信者のNome = entradalogin.get()ファイル "-----"、2530行目get self.tk.call無効なコマンド名 ".5288976.5207312" –

+0

コードにエラーがありますので、デバッガを使用してください。 –

+0

私に例を教えてもらえますか? Pls –

関連する問題