python - 如何创建闪烁的帧 - [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'
解决方案
推荐阅读
- r - R图中的乳胶括号
- javascript - vue 找不到 vuetify v-img 元素的动态源
- java - 为什么要使用 Consumer 和 Producer 而不是普通的 getter/setter?
- c# - 使用 DI 在 Startup.cs 中访问 NPGSQL
- shell - 在 shell 脚本中使用 "set --" 会导致 "bad number"
- regex - 我无法从未使用的运算符中删除零
- python - 在 Python 中使用时间戳重命名将文件移动到子目录
- java - jdk版本如何决定——Oracle发布周期更短
- groovy - 在groovy中映射,如何从键中获取值?
- php - 我可以从 mysql 表中获取值并将其设置为变量吗?