Jan-02-2019, 01:06 AM
Below is the code. I just need to know how to get the prints to print in the panel.
import wx import mysql.connector from mysql.connector import Error import csv panel = "global" average = "global" A1c = "global" class bucky(wx.Frame): def __init__(self, parent, id): wx.Frame.__init__(self, None, wx.ID_ANY, 'A1c', size=(400, 400)) panel = wx.Panel(self, wx.ID_ANY) button1 = wx.Button(panel, label='Import Data', pos=(10, 10), size=(75, 40)) self.Bind(wx.EVT_BUTTON, self.importdata, button1) self.Bind(wx.EVT_CLOSE, self.closewindow) button2 = wx.Button(panel, label='A1c', pos=(85, 10), size=(75, 40)) self.Bind(wx.EVT_BUTTON, self.showa1c, button2) self.Bind(wx.EVT_CLOSE, self.closewindow) button3 = wx.Button(panel, label='Exit', pos=(160, 10), size=(75, 40)) self.Bind(wx.EVT_BUTTON, self.closebutton, button3) self.Bind(wx.EVT_CLOSE, self.closewindow) # wx.StaticText(panel, -1, "This is static text", (10, 65)) # # custom = wx.StaticText(panel, -1, "This is custom static text", (10, 85), (260, -1,), wx.ALIGN_CENTER) # custom.SetForegroundColour('white') # custom.SetBackgroundColour('blue') def closebutton(self, event): self.Close(True) def closewindow(self, event): self.Destroy() def showa1c(self, event): try: con = mysql.connector.connect(host='localhost', database='meter', user='root', password='root') if con.is_connected(): db_Info = con.get_server_info() print("Connected to MySQL database... MySQL Server version on ", db_Info) cursor = con.cursor() cursor.execute("select database();") record = cursor.fetchone() print("Your connected to - ", record) except Error as e: print("Error while connecting to MySQL", e) cursor = con.cursor() cursor.execute( "SELECT SUM(hist) FROM readings WHERE rdate > now() - interval 91 day AND rtype = 0") hsum = cursor.fetchone()[0] cursor.execute( "SELECT SUM(scan) FROM readings WHERE rdate > now() - interval 91 day AND rtype = 1") ssum = cursor.fetchone()[0] cursor.execute( "SELECT count(hist) FROM readings WHERE rtype = 0 AND rdate > now() - interval 91 day ") hcount = cursor.fetchone()[0] cursor.execute( "SELECT count(scan) FROM readings WHERE rtype = 1 AND rdate > now() - interval 91 day") scount = cursor.fetchone()[0] con.commit() con.close() tsum = hsum + ssum tall = hcount + scount average = round(tsum / tall) A1c = (46.7 + average) / 28.7 print("Average: {}".format(average)) print('A1c {0:.1f}'.format(A1c)) def importdata(self, event): try: con = mysql.connector.connect(host='localhost', database='meter', user='root', password='root') if con.is_connected(): db_Info = con.get_server_info() print("Connected to MySQL database... MySQL Server version on ", db_Info) cursor = con.cursor() cursor.execute("select database();") record = cursor.fetchone() print("Your connected to - ", record) except Error as e: print("Error while connecting to MySQL", e) cursor = con.cursor() # ----------------------------------- INSERT DATA ------------------------------------- # cursor.execute('TRUNCATE TABLE readings') def inportdata(): f = open('summary2.csv', 'r') dr = csv.reader(f, delimiter='\t') next(dr) next(dr) next(dr) for row in dr: if row[4] == '': row[4] = 0 if row[3] == '': row[3] = 0 cursor.execute( 'INSERT INTO readings (id, rdate, rtype, hist, scan, novalog, novalogu, food, carbs, lantus, lantusu, notes, strip, ketone, na1, na2, na3, ptime, utime) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)', row) con.commit() if __name__ == '__main__': app = wx.App(False) frame = bucky(parent=None, id=-1) frame.Show() app.MainLoop()As you see I tried to mess around but could not figure it out. Everython works except no output in panel when it runs.