我正在尝试让我的第二个面板推出信息(例如,当您观看新闻时,您如何在屏幕底部或顶部看到它,信息不断推出)。除此之外,在我的代码中,我希望有这个单独的面板出现,它有多行推出不同的信息。有没有一种有效的方法来做到这一点?我的代码可以工作,但字符的输出速度并不顺畅,最终一些字母开始闪烁。
import time
import wx
class MainFrame(wx.Frame):
def __init__(self,parent):
wx.Frame.__init__(self,parent, title = 'Main Frame', size = (680,330))
self.Center()
self.panel = wx.Panel(self,size = (680,330))
self.pnl1 = wx.Panel(self.panel, size = (680,330))
self.pnl1.Show()
self.pnl1.SetBackgroundColour(wx.Colour(red= 150, green= 0, blue= 0))
my_label = wx.StaticText(self.pnl1, label = 'Click on this')
font = wx.Font(14, wx.MODERN, wx.NORMAL, wx.BOLD)
my_label.SetFont(font)
my_label.Center()
my_label.Bind(wx.EVT_LEFT_UP, self.func)
#----------------------------------------------------------------------
self.count1 = 0
self.count2 = 0
self.count3 = 0
self.count4 = 0
self.pnl2 = wx.Panel(self.panel, size=(800,300))
self.pnl2.Hide()
self.pnl2.SetBackgroundColour(wx.Colour(red= 0, green= 190, blue= 0))
self.lbl1 = ' Data ' * 10
self.my_str1 = ''
self.lbl2 = ' Info ' * 10
self.my_str2 = ''
self.lbl3 = ' bla bla ' * 10
self.my_str3 = ''
self.lbl4 = ' names ' * 10
self.my_str4 = ''
self.count1 = len(self.lbl1) - 1
self.count2 = len(self.lbl2) - 1
self.count3 = len(self.lbl3) - 1
self.count4 = len(self.lbl4) - 1
self.timer1 = wx.Timer(self)
self.timer1.Start(200)
self.Bind(wx.EVT_TIMER, self.OnTimer1, self.timer1)
self.timer2 = wx.Timer(self)
self.timer2.Start(200)
self.Bind(wx.EVT_TIMER, self.OnTimer2, self.timer2)
self.timer3 = wx.Timer(self)
self.timer3.Start(200)
self.Bind(wx.EVT_TIMER, self.OnTimer3, self.timer3)
self.timer4 = wx.Timer(self)
self.timer4.Start(200)
self.Bind(wx.EVT_TIMER, self.OnTimer4, self.timer4)
self.font = wx.Font(14, wx.MODERN, wx.NORMAL, wx.NORMAL)
#----------------------------------------------------------------------
def func(self, event):
self.pnl1.Hide()
self.pnl2.Show()
def OnTimer1(self,event):
if self.count1 < 0:
self.count1 = len(self.lbl1) - 1
self.my_str1 = ''
if self.count1 >= 0:
self.my_str1 = self.lbl1[self.count1] + self.my_str1
self.my_label1 = wx.StaticText(self.pnl2, label = self.my_str1, pos = (0,0))
self.my_label1.SetFont(self.font)
self.count1 = self.count1 - 1
def OnTimer2(self,event):
if self.count2 < 0:
self.count2 = len(self.lbl2) - 1
self.my_str2 = ''
if self.count2 >= 0:
self.my_str2 = self.lbl2[self.count2] + self.my_str2
self.my_label2 = wx.StaticText(self.pnl2, label = self.my_str2 , pos=(0,40))
self.my_label2.SetFont(self.font)
self.count2 = self.count2 - 1
def OnTimer3(self,event):
if self.count3 < 0:
self.count3 = len(self.lbl3) - 1
self.my_str3 = ''
if self.count3 >= 0:
self.my_str3 = self.lbl3[self.count3] + self.my_str3
self.my_label3 = wx.StaticText(self.pnl2, label = self.my_str3 , pos=(0,80))
self.my_label3.SetFont(self.font)
self.count3 = self.count3 - 1
def OnTimer4(self,event):
if self.count4 < 0:
self.count4 = len(self.lbl4) - 1
self.my_str4 = ''
if self.count4 >= 0:
self.my_str4 = self.lbl4[self.count4] + self.my_str4
self.my_label4 = wx.StaticText(self.pnl2, label = self.my_str4 , pos=(0,120))
self.my_label4.SetFont(self.font)
self.count4 = self.count4 - 1
#----------------------------------------------------------------------
#run code
if __name__ == '__main__':
app = wx.App(False)
frame = MainFrame(None)
frame.Show(True)
app.MainLoop()