Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import wx
- import sqlite3
- import wx.grid
- import os
- cwd = os.path.abspath(os.curdir)
- def connect(): #this is the sqlite3 connection
- conn = sqlite3.connect('RAMAN.db')
- return conn
- conn.close()
- def data_rows_count():# to count the rows in the database
- conn = connect()
- cur=conn.cursor()
- cur.execute("SELECT * FROM ELEMENT")
- rows=cur.fetchall()
- i=0
- for r in rows:
- i+=1
- return i
- class Example(wx.Frame):
- def __init__(self, parent, title):
- super(Example, self).__init__(parent, title=title, size=(800,600))
- self.InitUI()
- self.Layout()
- self.Centre()
- self.Show()
- def refresh_data(self):
- conn =connect()
- cur = conn.cursor()
- cur.execute("SELECT * FROM Phone")
- rows=cur.fetchall()
- for i in range (0,len(rows)):
- for j in range(0,4):
- cell = rows[i]
- self.grid_1.SetCellValue(i,j,str(cell[j]))
- def InitUI(self):
- self.grid_1 = wx.grid.Grid(self, -1, size=(1, 1))
- p = wx.Panel(self)
- r=data_rows_count()
- self.grid_1.CreateGrid(r, 1) #this is to create the grid with same rows as database
- self.grid_1.SetColLabelValue(0, ("SYMBOL"))
- self.grid_1.SetColSize(0, 12)
- bs = wx.BoxSizer(wx.VERTICAL)
- self.t1 = wx.TextCtrl(p,size = (120,30),style = wx.TE_MULTILINE |wx.TE_CENTER)
- bs.Add(self.t1, 1, wx.EXPAND)
- bs.Add(grid_1, 1, wx.EXPAND)
- self.refresh_data()
- def clk_h(self, event):
- r=data_rows_count
- for e in range(0,r):
- for f in range(0,103):
- self.grid_1.SetCellValue(e,f,"")
- conn=connect()
- cursor=conn.cursor()
- currsor.execute("SELECT SYMBOL FROM ELEMENT")
- conn.commit()
- rows=cursor.fetchall()
- btn = wx.Button(p, -1, h, (10,20))
- btn.myname = h
- btn.Bind(wx.EVT_BUTTON, self.OnClick, btn)
- grid_1.Add(btn, 0, wx.EXPAND)
- for i in range(len(rows)):
- for j in range(0,4):
- cell=rows[i]
- self.grid_1.SetCellValue(i,j,str(cell[j]))
- conn.close()
- event.Skip()
- p.SetSizer(bs)
- def OnClick(self, event):
- name = event.GetEventObject().myname
- self.t1.AppendText(name)
- self.t1.AppendText("\n")
- app = wx.App()
- Example(None, title = 'Grid demo')
- app.MainLoop()
Add Comment
Please, Sign In to add comment