Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
Search Box in python that connect to localhost db

Hi everyone I am developing a project for my school and in that same project I need to have a search box in python, I already have more or less the idea of ​​how it develops but it is giving some errors. Sorry for my bad english but it is not my first language. here I leave my code.

import mysql.connector
from tkinter import *
con = mysql.connector.connect(
    host="localhost",
    user="root",
    passwd="",
    database="testing"
)
top = Tk()
top.title('Search form')
top.geometry("200x200")
cursor = con.cursor()
name_box = Entry()
name_box.pack(side = RIGHT, expand = True)


def search(tup):
    try:
        person_name = name_box.get()
        cursor.execute("SELECT * FROM `admin` WHERE `email`=%s",name.box.get())
        return (cursor.fetchone())
    


        self.button = Button(self.frame, text="Display text", command=search)
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

your code is missing a vital part see at the end the last commandm so you can enter as many seaches as you like

you were on the right track, but as you can see, mysql needs somemore lines

import mysql.connector
import datetime
from mysql.connector.cursor import MySQLCursorPrepared
from tkinter import *

mydb = mysql.connector.connect(
     host="localhost",
     user="root",
     passwd="password",
     database="testdb"
)
mycursor = mydb.cursor(cursor_class=MySQLCursorPrepared)
top = Tk()
top.title('Search form')
top.geometry("200x200")
name_box = Entry()
name_box.pack(side = RIGHT, expand = True)

def get_name():
    global person_name
    person_name = name_box.get()
    try:
        sql1="SELECT `mytable`.`Name` FROM `testdb`.`mytable` WHERE Name = %s;"
        mycursor.execute(sql1,(person_name,))
        records = mycursor.fetchall()
        for x in records:
            print(x)
    except mysql.connector.Error as err:
        print("Something went wrong: {}".format(err))

person_name = ""
button = Button(top, text="Display text", command=get_name)
button.pack()


mainloop()
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda