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()









share|improve this question









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 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 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















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()









share|improve this question









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 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 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













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()









share|improve this question









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






share|improve this question









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.











share|improve this question









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.









share|improve this question




share|improve this question








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 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 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


















  • 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 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
















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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Layne is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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






























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.










 

draft saved


draft discarded


















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.















 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Catalogne

Violoncelliste

Héron pourpré