# -*- coding: utf-8 -*-
import wx.html2
import sqlite3
class MainFream(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, style=wx.DEFAULT_FRAME_STYLE)
self.htmlweb = wx.html2.WebView.New(self, size=(0, 0),
backend=wx.html2.WebViewBackendIE
#backend=wx.html2.WebViewBackendWebKit
)
self.conn = sqlite3.connect("main.db")
self.cursor = self.conn.cursor()
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.AutoRefresh, self.timer)
self.timer.Start(10000)
self.HtmlCode()
def AutoRefresh(self, event):
self.HtmlCode()
def DataBase(self):
self.color = ('#00ff00', 'red')
self.selectcolor = []
self.cursor.execute('select *from clinic1')
for self.data1 in self.cursor.fetchall(): pass
for n in range(4, 7):
if self.data1[n] == 'True': self.selectcolor.append(self.color[0])
else: self.selectcolor.append(self.color[1])
self.cursor.execute('select *from clinic2')
for self.data2 in self.cursor.fetchall(): pass
for n in range(4, 7):
if self.data2[n] == 'True': self.selectcolor.append(self.color[0])
else: self.selectcolor.append(self.color[1])
self.cursor.execute('select *from clinic3')
for self.data3 in self.cursor.fetchall(): pass
def HtmlCode(self):
self.DataBase()
self.HTML_CODE = """
<!DOCTYPE HTML>
<html lang="ko">
<head>
<meta charset='utf-8'>
<title>HTML TEST</title>
<style type='text/css'>
html{{
background-image:url(D:/python3/PycharmProjects/untitled/3.png);
}}
table{{
width:100%;
}}
table, caption, th, td{{
border:2px solid lightgray;
border-collapse:collapse;
height:0px;
color:white;
text-align:center;
font-size:155%;
font-style:normal;
font-weight:bold;
font-family:Malgun Gothic;
}}
caption{{
background-color:white; color:#0d0d0d; font-size:250%; font-weight:bold;
}}
th{{
background-color:white; color:#0d0d0d; font-size:145%; font-weight:bold;
}}
caption, th{{
background-image:url(D:/python3/PycharmProjects/untitled/bg5.png);
}}
</style>
</head>
<body scroll='no'>
<table>
<caption>T E S T Main</caption>
<thead>
<tr bgcolor='ffffff'>
<th>T E S T1</th>
<th>T E S T2</th>
<th>T E S T3</th>
<th>T E S T4</th>
<th>T E S T5</th>
<th>T E S T6</th>
</tr>
</thead>
<tbody>
<tr style='background: url(D:/python3/PycharmProjects/untitled/bg1.png)'>
<td>{0}</td>
<td>{1}</td>
<td>{2}</td>
<td><p style='color:{3}'>{4}</p></td>
<td><p style='color:{5}'>{6}</p></td>
<td><p style='color:{7}'>{8}</p></td>
</tr>
<tr style='background: url(D:/python3/PycharmProjects/untitled/bg1.png)'>
<td>{9}</td>
<td>{10}</td>
<td>{11}</td>
<td><p style='color:{12}'>{13}</p></td>
<td><p style='color:{14}'>{15}</p></td>
<td><p style='color:{16}'>{17}</p></td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="6"><marquee><font color='cyan'>{18}</font></marquee></td>
</tr>
</tfoot>
</table>
</body>
</html>
"""
self.DataIn()
def DataIn(self):
self.htmlweb.SetPage(self.HTML_CODE.format(
self.data1[1], self.data1[2], self.data1[3], self.selectcolor[0], self.data1[4], self.selectcolor[1], self.data1[5], self.selectcolor[2], self.data1[6],
self.data2[1], self.data2[2], self.data2[3], self.selectcolor[3], self.data2[4], self.selectcolor[4], self.data2[5], self.selectcolor[5], self.data2[6],
self.data3[1]), "")
if __name__ == '__main__':
app = wx.App()
fream = MainFream()
fream.Show(True)
app.MainLoop()
Wir verwenden Fenster auf den Bildschirm zu testen, die Datenbank jede Stunde Laden wx.html2
und wx.timer
verwenden.Ich möchte blinken vermeiden, wenn ich es mit laden wx.timer
Jedes Mal, wenn ich Daten mit wx.timer
lade, blinkt das Hintergrundbild weiß auf der background-image: url (D: /python3/PycharmProjects/untitled/3.png);
.
Können Sie das blinkende Problem nicht lösen?
Ich möchte auch nicht wx.timer verwenden, aber ich möchte den geänderten Inhalt in Echtzeit wiedergeben, wenn nur der Datenbankwert geändert wird. Gibt es in diesem Fall ein Modul?