Question: Hello, I am trying to display a sql database in a python GUI but dont know how to go about it. The GUI is suppose

Hello,

I am trying to display a sql database in a python GUI but dont know how to go about it. The GUI is suppose to display restraunt info when a button is clicked in the GUI below but I cant get it to display in the messagebox... the information will only display in the console.

import sqlite3 from sqlite3 import Error

def create_connection(db_file): """ Connection for the database """ try: conn = sqlite3.connect(db_file) return conn except Error as e: print(e)

return None

def Display_all(conn):

cur = conn.cursor() Query = "SELECT * " \ "FROM Restraunts " \

cur.execute(Query)

rows = cur.fetchall() for row in rows: print(row)

class All(): def __init__(self): self.MainWindow = tkinter.Tk() self.Button_F = tkinter.Frame(self.MainWindow) self.Disp_Button = tkinter.Button(self.Button_F, text = 'Find Restraunts', command = self.Display) self.Quit_Button = tkinter.Button(self.Button_F, text = 'Quit',command=self.MainWindow.destroy) self.Disp_Button.pack(side = 'left') self.Quit_Button.pack(sid = 'left') self.Button_F.pack() tkinter.mainloop() def Display(self): Rest = str(Display_all(conn)) tkinter.messagebox.showinfo('Restruants',Rest)

All()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!