首页 > 解决方案 > 如何创建闪烁的帧 - [tkinter]

问题描述

x经过数小时的时间后,我一直在努力让两帧闪烁,我真的不确定该怎么做。我也调查.sleep.after。无论我如何尝试让它工作,它总是会等待x一段时间然后显示我想要显示的帧。我想要的结果应该是这样的:https ://multiplesclerosis.net/wp-content/uploads/2018/02/33518_custom.gif 。

任何帮助都会很棒。

class DataPage(tk.Frame, tk.Tk):
... (non-important methods)
    def vepSlideShow(self):
        root = tk.Tk()
        root.title("P300")
        root.state("zoomed")
        container = tk.Frame(root)
        container.pack(side="top", fill="both", expand=True)

        frames = {}

        frames[WBChecker] = WBChecker(container, root)
        frames[WBChecker].grid(row=0, column=1, sticky="nsew")
        frames[BWChecker] = BWChecker(container, root)
        frames[BWChecker].grid(row=0, column=1, sticky="nsew")


        def test():
            print("Hit")
            currentwin = frames[BWChecker]
            nextwin = frames[BWChecker] if currentwin == frames[BWChecker] else frames[BWChecker]
            root.after(5000, test())

        test()
        root.mainloop()


    def changeWindow(self, frame1, frame2):
        print("Hit")
        frame1.after(5000, frame1.tkraise())


class WBChecker(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        canvas = tk.Canvas(self)
        canvas.config(height=1080, width=1920)
        canvas.pack()
        SIZE=126
        color = 'white'

        for y in range(8):

            for x in range(16):
                x1 = x*SIZE
                y1 = y*SIZE
                x2 = x1 + SIZE
                y2 = y1 + SIZE
                canvas.create_rectangle((x1, y1, x2, y2), fill=color)
                if color == 'white':
                    color = 'black'
                else:
                    color = 'white'

            if color == 'white':
                color = 'black'
            else:
                color = 'white'

class BWChecker(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        canvas2 = tk.Canvas(self)
        canvas2.config(height=1080, width=1920)
        canvas2.pack()

        SIZE=126
        color = 'black'

        for y in range(8):

            for x in range(16):
                x1 = x*SIZE
                y1 = y*SIZE
                x2 = x1 + SIZE
                y2 = y1 + SIZE
                canvas2.create_rectangle((x1, y1, x2, y2), fill=color)
                if color == 'white':
                    color = 'black'
                else:
                    color = 'white'

            if color == 'white':
                color = 'black'
            else:
                color = 'white'
    def vepSlideShow(self):
        root = tk.Tk()
        root.title("P300")
        root.state("zoomed")
        container = tk.Frame(root)
        container.pack(side="top", fill="both", expand=True)

        frames = {}

        frames[WBChecker] = WBChecker(container, root)
        frames[WBChecker].grid(row=0, column=1, sticky="nsew")
        frames[BWChecker] = BWChecker(container, root)
        frames[BWChecker].grid(row=0, column=1, sticky="nsew")


        def test():
            print("Hit")
            currentwin = frames[BWChecker]
            nextwin = frames[BWChecker] if currentwin == frames[BWChecker] else frames[BWChecker]
            root.after(5000, test())

        test()
        root.mainloop()


    def changeWindow(self, frame1, frame2):
        print("Hit")
        frame1.after(5000, frame1.tkraise())


class WBChecker(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        canvas = tk.Canvas(self)
        canvas.config(height=1080, width=1920)
        canvas.pack()
        SIZE=126
        color = 'white'

        for y in range(8):

            for x in range(16):
                x1 = x*SIZE
                y1 = y*SIZE
                x2 = x1 + SIZE
                y2 = y1 + SIZE
                canvas.create_rectangle((x1, y1, x2, y2), fill=color)
                if color == 'white':
                    color = 'black'
                else:
                    color = 'white'

            if color == 'white':
                color = 'black'
            else:
                color = 'white'

class BWChecker(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        canvas2 = tk.Canvas(self)
        canvas2.config(height=1080, width=1920)
        canvas2.pack()

        SIZE=126
        color = 'black'

        for y in range(8):

            for x in range(16):
                x1 = x*SIZE
                y1 = y*SIZE
                x2 = x1 + SIZE
                y2 = y1 + SIZE
                canvas2.create_rectangle((x1, y1, x2, y2), fill=color)
                if color == 'white':
                    color = 'black'
                else:
                    color = 'white'

            if color == 'white':
                color = 'black'
            else:
                color = 'white'

标签: pythonpython-3.xtkinter

解决方案


推荐阅读