I'm having a little problem with this code! Basically, I'm testing a feature for a piece of software, and the idea was to animate these windows. So far, it's working fine. When the top window expands, the bottom one shrinks. However, this creates a small bug in frame 2. It kind of flickers, and this happens simply because the position doesn't keep up with the window's expansion and vice versa. However, I haven't been able to find a solution to this issue yet, so I decided to ask the community for help. I've uploaded a video to YouTube so you can visualize the bug and understand it better (https://youtu.be/AGQQ_u_qvD4).
import customtkinter as CTk
main_layout = CTk.CTk()
main_layout.geometry(f"{600}x{350}")
h1, h2 = 50, 170
y2 = 150
animation_running = False
def start_animation(to_frame):
global h1, h2, y2, animation_running
if animation_running:
return
animation_running = True
def step():
global h1, h2, y2, animation_running
done = False
if to_frame and h1 < 170:
y2 += 10
h1 += 10
h2 -= 10
elif not to_frame and h2 < 170:
y2 -= 10
h1 -= 10
h2 += 10
else:
done = True
frame_1.configure(height=h1)
frame_2.configure(height=h2)
frame_2.place(y=y2)
if not done:
main_layout.after(10, step)
else:
animation_running = False
step()
frame_1 = CTk.CTkFrame(master=main_layout, width=240, height=h1, corner_radius=25)
frame_1.place(x=40, y=80)
button1= CTk.CTkButton(master=frame_1, text='1', width=20, height=20, command=lambda:start_animation(True))
button1.place(x=0, y=0)
frame_2 = CTk.CTkFrame(master=main_layout, width=240, height=h2, corner_radius=25)
frame_2.place(x=40, y=y2)
button2= CTk.CTkButton(master=frame_2, text='2', width=20, height=20, command=lambda:start_animation(False))
button2.place(x=0, y=0)
main_layout.mainloop()
```in separate line to correctly format and highlight code because text directly after```is treated as information what language was used in code - ie.```pythonor```htmlto select python or html for highlightning.