Python tkinter&pymysql - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: Python tkinter&pymysql (/thread-9533.html) |
Python tkinter&pymysql - xgrzeniu - Apr-15-2018 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() RE: Python tkinter&pymysql - Larz60+ - Apr-15-2018 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. RE: Python tkinter&pymysql - xgrzeniu - Apr-15-2018 ok, how do you propose to change this code ?? Python is just learning Python RE: Python tkinter&pymysql - Larz60+ - Apr-15-2018 You should do a python tutorial, suggest: https://www.python-course.eu/ |