tkinter application - unable to search and display sqlite3 database results
up vote
0
down vote
favorite
I'm building a simple inventory application in python and tkinter using sqlite3 as my database. The data entry works great, but for 2 weeks now I've been stuck on getting a search function working. I've tried numerous examples from this site and other places, but I continue to get errors or no output. Some of my functions have returned all results in the database, otherwise its an error or simply nothing. I can't figure out where I'm going wrong. Here is the current code (The search function has changed dozens of times, this is some of the latest code/version/attempt).
import tkinter as tk
from tkinter import Frame, TOP, LEFT, RIGHT, Label, Entry, StringVar, Text,
END
import time
import tkinter.messagebox as messagebox
import sqlite3 as sqlite
conn = sqlite.connect('inventory.db')
c = conn.cursor
def create_table():
try:
conn.execute('''CREATE TABLE if not exists Inventory (
HostName TEXT, User TEXT,
Newhostname TEXT, Location TEXT)''')
print('Table created successfully')
except Error as e:
pass
create_table()
conn.close()
Hostname=StringVar()
User=StringVar()
Newh=StringVar()
Location=StringVar()
Search=StringVar()
# ===== Display field ==========
textdisplay = Text(f2, height = 20, width=50, bd=15, font=('arial',
16, 'bold'))
textdisplay.grid(row=1, column=0, padx=(15,15))
#=============== SEARCH FUNCTION
def search_button():
conn = sqlite.connect('inventory.db')
c = conn.cursor()
c.execute("SELECT * FROM Inventory")
for row in c.fetchall():
print(row)
textdisplay.insert(END, "ttSearch Results: nn")
textdisplay.insert(END, "Hostname: tt" + Hostname.get() + "nn")
textdisplay.insert(END, "User: tt" + User.get() + "nn")
textdisplay.insert(END, "New Hostname: tt" + Newh.get() + "nn")
textdisplay.insert(END, "Location: tt" + Location.get() + "nn")
conn.close()
python-3.x tkinter sqlite3
New contributor
Layne is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
I'm building a simple inventory application in python and tkinter using sqlite3 as my database. The data entry works great, but for 2 weeks now I've been stuck on getting a search function working. I've tried numerous examples from this site and other places, but I continue to get errors or no output. Some of my functions have returned all results in the database, otherwise its an error or simply nothing. I can't figure out where I'm going wrong. Here is the current code (The search function has changed dozens of times, this is some of the latest code/version/attempt).
import tkinter as tk
from tkinter import Frame, TOP, LEFT, RIGHT, Label, Entry, StringVar, Text,
END
import time
import tkinter.messagebox as messagebox
import sqlite3 as sqlite
conn = sqlite.connect('inventory.db')
c = conn.cursor
def create_table():
try:
conn.execute('''CREATE TABLE if not exists Inventory (
HostName TEXT, User TEXT,
Newhostname TEXT, Location TEXT)''')
print('Table created successfully')
except Error as e:
pass
create_table()
conn.close()
Hostname=StringVar()
User=StringVar()
Newh=StringVar()
Location=StringVar()
Search=StringVar()
# ===== Display field ==========
textdisplay = Text(f2, height = 20, width=50, bd=15, font=('arial',
16, 'bold'))
textdisplay.grid(row=1, column=0, padx=(15,15))
#=============== SEARCH FUNCTION
def search_button():
conn = sqlite.connect('inventory.db')
c = conn.cursor()
c.execute("SELECT * FROM Inventory")
for row in c.fetchall():
print(row)
textdisplay.insert(END, "ttSearch Results: nn")
textdisplay.insert(END, "Hostname: tt" + Hostname.get() + "nn")
textdisplay.insert(END, "User: tt" + User.get() + "nn")
textdisplay.insert(END, "New Hostname: tt" + Newh.get() + "nn")
textdisplay.insert(END, "Location: tt" + Location.get() + "nn")
conn.close()
python-3.x tkinter sqlite3
New contributor
Layne is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Can you trim down your code? It makes it easier to read if we don't have to sift through a bunch of code that's not related to your problem. Beyond that, your query isSELECT * FROM inventory. Getting ever record from that table is exactly what you've asked for.
– mypetlion
Nov 21 at 18:53
Because I need all the data from that user. Not just all usernames or all hostnames. Say I need to find the hostname and location for a user. I search for that user and if a record is found, the data for that user is displayed. If I change * to User, it's just going to spit out all users which is useless.
– Layne
Nov 21 at 19:06
But you don't search for all data from a user. You search for all data for all users. It sounds like you need aWHEREclause so sqlite only pulls the records you want.
– mypetlion
Nov 21 at 19:09
your code is not complete to produce such error.
– AD WAN
2 days ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm building a simple inventory application in python and tkinter using sqlite3 as my database. The data entry works great, but for 2 weeks now I've been stuck on getting a search function working. I've tried numerous examples from this site and other places, but I continue to get errors or no output. Some of my functions have returned all results in the database, otherwise its an error or simply nothing. I can't figure out where I'm going wrong. Here is the current code (The search function has changed dozens of times, this is some of the latest code/version/attempt).
import tkinter as tk
from tkinter import Frame, TOP, LEFT, RIGHT, Label, Entry, StringVar, Text,
END
import time
import tkinter.messagebox as messagebox
import sqlite3 as sqlite
conn = sqlite.connect('inventory.db')
c = conn.cursor
def create_table():
try:
conn.execute('''CREATE TABLE if not exists Inventory (
HostName TEXT, User TEXT,
Newhostname TEXT, Location TEXT)''')
print('Table created successfully')
except Error as e:
pass
create_table()
conn.close()
Hostname=StringVar()
User=StringVar()
Newh=StringVar()
Location=StringVar()
Search=StringVar()
# ===== Display field ==========
textdisplay = Text(f2, height = 20, width=50, bd=15, font=('arial',
16, 'bold'))
textdisplay.grid(row=1, column=0, padx=(15,15))
#=============== SEARCH FUNCTION
def search_button():
conn = sqlite.connect('inventory.db')
c = conn.cursor()
c.execute("SELECT * FROM Inventory")
for row in c.fetchall():
print(row)
textdisplay.insert(END, "ttSearch Results: nn")
textdisplay.insert(END, "Hostname: tt" + Hostname.get() + "nn")
textdisplay.insert(END, "User: tt" + User.get() + "nn")
textdisplay.insert(END, "New Hostname: tt" + Newh.get() + "nn")
textdisplay.insert(END, "Location: tt" + Location.get() + "nn")
conn.close()
python-3.x tkinter sqlite3
New contributor
Layne is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I'm building a simple inventory application in python and tkinter using sqlite3 as my database. The data entry works great, but for 2 weeks now I've been stuck on getting a search function working. I've tried numerous examples from this site and other places, but I continue to get errors or no output. Some of my functions have returned all results in the database, otherwise its an error or simply nothing. I can't figure out where I'm going wrong. Here is the current code (The search function has changed dozens of times, this is some of the latest code/version/attempt).
import tkinter as tk
from tkinter import Frame, TOP, LEFT, RIGHT, Label, Entry, StringVar, Text,
END
import time
import tkinter.messagebox as messagebox
import sqlite3 as sqlite
conn = sqlite.connect('inventory.db')
c = conn.cursor
def create_table():
try:
conn.execute('''CREATE TABLE if not exists Inventory (
HostName TEXT, User TEXT,
Newhostname TEXT, Location TEXT)''')
print('Table created successfully')
except Error as e:
pass
create_table()
conn.close()
Hostname=StringVar()
User=StringVar()
Newh=StringVar()
Location=StringVar()
Search=StringVar()
# ===== Display field ==========
textdisplay = Text(f2, height = 20, width=50, bd=15, font=('arial',
16, 'bold'))
textdisplay.grid(row=1, column=0, padx=(15,15))
#=============== SEARCH FUNCTION
def search_button():
conn = sqlite.connect('inventory.db')
c = conn.cursor()
c.execute("SELECT * FROM Inventory")
for row in c.fetchall():
print(row)
textdisplay.insert(END, "ttSearch Results: nn")
textdisplay.insert(END, "Hostname: tt" + Hostname.get() + "nn")
textdisplay.insert(END, "User: tt" + User.get() + "nn")
textdisplay.insert(END, "New Hostname: tt" + Newh.get() + "nn")
textdisplay.insert(END, "Location: tt" + Location.get() + "nn")
conn.close()
python-3.x tkinter sqlite3
python-3.x tkinter sqlite3
New contributor
Layne is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Layne is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited Nov 21 at 18:55
New contributor
Layne is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Nov 21 at 18:49
Layne
14
14
New contributor
Layne is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Layne is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Layne is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Can you trim down your code? It makes it easier to read if we don't have to sift through a bunch of code that's not related to your problem. Beyond that, your query isSELECT * FROM inventory. Getting ever record from that table is exactly what you've asked for.
– mypetlion
Nov 21 at 18:53
Because I need all the data from that user. Not just all usernames or all hostnames. Say I need to find the hostname and location for a user. I search for that user and if a record is found, the data for that user is displayed. If I change * to User, it's just going to spit out all users which is useless.
– Layne
Nov 21 at 19:06
But you don't search for all data from a user. You search for all data for all users. It sounds like you need aWHEREclause so sqlite only pulls the records you want.
– mypetlion
Nov 21 at 19:09
your code is not complete to produce such error.
– AD WAN
2 days ago
add a comment |
Can you trim down your code? It makes it easier to read if we don't have to sift through a bunch of code that's not related to your problem. Beyond that, your query isSELECT * FROM inventory. Getting ever record from that table is exactly what you've asked for.
– mypetlion
Nov 21 at 18:53
Because I need all the data from that user. Not just all usernames or all hostnames. Say I need to find the hostname and location for a user. I search for that user and if a record is found, the data for that user is displayed. If I change * to User, it's just going to spit out all users which is useless.
– Layne
Nov 21 at 19:06
But you don't search for all data from a user. You search for all data for all users. It sounds like you need aWHEREclause so sqlite only pulls the records you want.
– mypetlion
Nov 21 at 19:09
your code is not complete to produce such error.
– AD WAN
2 days ago
Can you trim down your code? It makes it easier to read if we don't have to sift through a bunch of code that's not related to your problem. Beyond that, your query is
SELECT * FROM inventory. Getting ever record from that table is exactly what you've asked for.– mypetlion
Nov 21 at 18:53
Can you trim down your code? It makes it easier to read if we don't have to sift through a bunch of code that's not related to your problem. Beyond that, your query is
SELECT * FROM inventory. Getting ever record from that table is exactly what you've asked for.– mypetlion
Nov 21 at 18:53
Because I need all the data from that user. Not just all usernames or all hostnames. Say I need to find the hostname and location for a user. I search for that user and if a record is found, the data for that user is displayed. If I change * to User, it's just going to spit out all users which is useless.
– Layne
Nov 21 at 19:06
Because I need all the data from that user. Not just all usernames or all hostnames. Say I need to find the hostname and location for a user. I search for that user and if a record is found, the data for that user is displayed. If I change * to User, it's just going to spit out all users which is useless.
– Layne
Nov 21 at 19:06
But you don't search for all data from a user. You search for all data for all users. It sounds like you need a
WHERE clause so sqlite only pulls the records you want.– mypetlion
Nov 21 at 19:09
But you don't search for all data from a user. You search for all data for all users. It sounds like you need a
WHERE clause so sqlite only pulls the records you want.– mypetlion
Nov 21 at 19:09
your code is not complete to produce such error.
– AD WAN
2 days ago
your code is not complete to produce such error.
– AD WAN
2 days ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Layne is a new contributor. Be nice, and check out our Code of Conduct.
Layne is a new contributor. Be nice, and check out our Code of Conduct.
Layne is a new contributor. Be nice, and check out our Code of Conduct.
Layne is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418745%2ftkinter-application-unable-to-search-and-display-sqlite3-database-results%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you trim down your code? It makes it easier to read if we don't have to sift through a bunch of code that's not related to your problem. Beyond that, your query is
SELECT * FROM inventory. Getting ever record from that table is exactly what you've asked for.– mypetlion
Nov 21 at 18:53
Because I need all the data from that user. Not just all usernames or all hostnames. Say I need to find the hostname and location for a user. I search for that user and if a record is found, the data for that user is displayed. If I change * to User, it's just going to spit out all users which is useless.
– Layne
Nov 21 at 19:06
But you don't search for all data from a user. You search for all data for all users. It sounds like you need a
WHEREclause so sqlite only pulls the records you want.– mypetlion
Nov 21 at 19:09
your code is not complete to produce such error.
– AD WAN
2 days ago