Python Forum
Python tkinter&pymysql
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python tkinter&pymysql
#1
Gentlemen, can you help me? I have a piece of code. There are two text fields 1 (tpn) 2 (name) in the script. In the mysql database I also have two tpn columns and a name. I would like to insert the contents of the searched value from the database in texbox2 after entering into textbox1 from the column name for the searched value. Will you help me ??

from tkinter import *
import pymysql



window=Tk()
window.title("Python")
menu = Menu(window)


conn= pymysql.connect(host='106.90.5.2',user='admin',password='admin123',db='Base')

a= conn.cursor ()
sql = 'select nazwa from karta_artykulu;'
countrow = a.execute(sql)
#print("Number od rows :",countrow)
data = a.fetchall()
print (data)



 #----------------------------------------------------------------------------Wprowadzanie textbox do nazw
author_text=StringVar()
al=Entry(window,textvariable=author_text,width=40,font=('CALIBRI', 12))
al.grid(row=2,column=1)


 #----------------------------------------------------------------------------textbox art
author_text=StringVar()
t1=Entry(window,textvariable=author_text,width=20,font=('CALIBRI', 12))
t1.grid(row=2,column=2)



#buttons
b1=Button(window,text="PRINT",width=18,fg="red",font=('CALIBRI', 14, 'bold'))
b1.grid(row=15,column=7)


window.mainloop()
Reply
#2
you're assigning the same StringVar to two Entry widgets, which will probably (not sure) cause issues.
I would use two separate variables.
You set and get the values, for example:
author_text.set(value)
in addition, after you do a a.fetch_all()
you need to select the rows from data.

Also, you should use meaningful names, not single letters which is bad practice.
Reply
#3
ok, how do you propose to change this code ?? Python is just learning Python
Reply
#4
You should do a python tutorial, suggest: https://www.python-course.eu/
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020