Python Forum
[Tkinter] Link text field to separate python file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Link text field to separate python file
#1
Hi Guys,

I am trying to take the values of a text field in my GUI.py file, and feed the values in to a search option in Retrieve.py. So when the user types in a username and presses a button, the username they have searched for is then transferred to the retrieve.py file to run searches against a database. I am really not too sure how to do this. I am using Tkinter.

This is my retrieve code:

def username():
   con.sqlite3.connect('database')
    c = conn.cursor
    name = raw_input ("Enter Username")
    c.execute("SELECT users FROM Results WHERE users LIKE '%"+name+"%';")
    data = c.fetchall()
    print (data)
    c.close
    conn.close
Reply
#2
Do not post code as you did. I added code tags in the proper manner.

The gui code should use a get user button that is bound to the retrieve function
this can be done in the command argument of the button instance or with a separate
bind statement attached to the button. In either case, you will have to provide an event hook
as an argument in retrieve.
Reply
#3
.close is a method.  You need parenthases to call it.  c.close() and conn.close().

And please, don't write sql queries like that.  Use the string formatting the db engine provides, so the values are escaped properly (otherwise a "well written" text snippet could "accidentally" delete your entire database).  So maybe
user = "%{}%".format(name)
c.execute("select users from results where users like ?", user)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] field in db as text rwahdan 6 2,832 Jul-16-2021, 07:07 AM
Last Post: rwahdan
  [Tkinter] Override the paste function(copy from excel file - paste in separate tkinter entryes) AndreiV 3 4,557 Jun-05-2020, 04:46 PM
Last Post: AndreiV
  [Tkinter] Unable to get current contents of the entry field where the content is the file path pmpinaki 1 2,193 Apr-18-2020, 06:45 PM
Last Post: deanhystad
  [Kivy] Can't link .kw file with main.py Allpha 2 3,401 Aug-14-2017, 08:05 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

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