Home > Mobile >  How wxpython GUI from SQL server access to real-time data display?
How wxpython GUI from SQL server access to real-time data display?

Time:10-10

Hi,

I have a simple application, want to read data from the SQL server, and real-time display on the wxpython write a GUI interface, at the moment, I can read data from a SQL server, but can't do real-time display, that is to say, when the database's data changes, the data on the GUI interface can't update, please help to give directions, grateful,
Attach my code below: Python 3.5, Win10


# - * - coding: utf-8 - * -
The import wx
The import wx. Adv
The import wx. Grid
The import sys
The import pyodbc
The import time

Bgcolor=(220220220)
The class Mywin (wx. Frame) :
Def __init__ (self, parent, title) :
Self, super (Mywin) __init__ (the parent, the title=title, size=(600320))
The self. The InitUI ()

Def InitUI (self) :
Nb=wx. Notebook (self)
Nb. The AddPage (MyPanel3 (nb), "Table")
The self. The Centre ()
The self. The Show (True)

Def retrieve_data_fromdb () :
# SQL Server configuration
Server='localhost'
The db='* * *
User='sa'
The PWD='* * * * * *

Src_db=pyodbc. Connect (r 'DRIVER=11.0} {SQL Server Native Client; SERVER='+ SERVER +'; The DATABASE='+ db +'; UID='+ user +'; The PWD='+ PWD)
Cur=src_db. Cursor ()

The select='select * from real_time_test'

Cur. Execute (select)
Rows=cur. Fetchone ()
Wind_spd=rows [0]
Site_pwr=rows [1]
Acv_pr_setpnt=rows [2]
Park_pbl_cap=rows [3]
Tol_cur=rows [4]
Tol_non_prod=rows [5]
Data=https://bbs.csdn.net/topics/[]
Data. Append (wind_spd)
Data. Append (site_pwr)
Data. Append (acv_pr_setpnt)
Data. Append (park_pbl_cap)
Data. Append (tol_cur)
Data. Append (tol_non_prod)
The return data
MIT ()
cur.comCur. Close ()
Src_db. Close ()

The class MyPanel3 (wx. The Panel) :
Def __init__ (self, parent) :
Super (MyPanel3, self) __init__ (parent)
Self. SetBackgroundColour (bgcolor)
The self. The Bind (wx. EVT_PAINT, self. OnPaint)

Title_NDC=wx. StaticText (self - 1, "Real time signals," (30, 22))
Title_NDC. SetForegroundColour ((0, 0, 255))
Wx. StaticText (self - 1, "1. The Wind Speed", (35, 75))
Wx. StaticText (self - 1, 2. Site Power, (35, 95))
Wx. StaticText (self - 1, "Instant", (300, 45))

Wx. StaticText (self - 1, "m/s", (340, 75))
Wx. StaticText (self - 1, "kW", (340, 95))

A=retrieve_data_fromdb ()
Wind_spd_val=wx. StaticText (self - 1, a [0], (300, 75))
Wind_spd_val. SetForegroundColour ((0, 0, 255))


Def OnPaint (self, event) :
PDC=wx. PaintDC (self)
The gc=wx. GCDC (PDC)
The gc. The Clear ()

Brush_rec=wx. Brush (bgcolor)
Gc. SetBrush (brush_rec)
Gc. SetPen (wx. Pen (" black ", 2))

X1=20
Y1=30
W1=500
H1=180
The radius=3
Gc. DrawRoundedRectangle (x1, y1, w1, h1, radius)


Ex.=wx App ()
Mywin (None, 'My example)
Ex. The MainLoop ()
  •  Tags:  
  • Qt
  • Related