Jumat, 10 Oktober 2025

WXPYTHON - TEXT ANIMATION

 



import wx


class TextAnimationFrame(wx.Frame):

    def __init__(self, parent, title):

        super().__init__(parent, title=title, size=(500, 200))


        panel = wx.Panel(self)

        vbox = wx.BoxSizer(wx.VERTICAL)


        self.animated_text = wx.StaticText(panel, label="", style=wx.ALIGN_CENTER)

        font = wx.Font(18, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)

        self.animated_text.SetFont(font)

        vbox.Add(self.animated_text, 1, wx.EXPAND | wx.ALL, 20)


        panel.SetSizer(vbox)

        self.Layout()


        self.text_to_animate = ".......................Hello, wxPython!"

        self.current_char_index = 0


        self.timer = wx.Timer(self)

        self.Bind(wx.EVT_TIMER, self.on_timer, self.timer)

        self.timer.Stop()

        self.timer.Start(200)  # Update every 100 milliseconds


    def on_timer(self, event):

        if self.current_char_index < len(self.text_to_animate):

            current_displayed_text = self.text_to_animate[:self.current_char_index + 1]

            self.animated_text.SetLabel(current_displayed_text)

            self.current_char_index += 1

        else:

            self.timer.Stop() # Stop the timer once animation is complete

            # Optional: Reset or loop the animation

            # self.current_char_index = 0

            # self.timer.Start(100)

            



if __name__ == '__main__':

    app = wx.App()

    frame = TextAnimationFrame(None, "wxPython Text Animation")

    frame.Show()

    app.MainLoop()

Tidak ada komentar: