I want to create a line in the Tkinter and after changing the height I need to delete the previous line and create a new line with the new height, this is a repeated process.
To this, I read the tutorial of the Tkinter of python and I think the After
method might be useful. So, I write my idea but it is not a good method and I cannot create it. Also, I searched about a Shown
event in the Tkinter, but I did not find the Shown
event in the Tkinter for the window.
Here is my suggested code:
from tkinter import *
from tkinter import messagebox
import numpy as np
import random
window = Tk()
window.geometry("600x400+650+200")
window.resizable(0, 0)
window.title("Ball Balancing Game - QLearning")
canvas = Canvas()
def uptodate():
canvas.delete(line1)
line1 = canvas.create_line(100, 200, 500, h)
# for i in range(len(h) - 1):
# for j in range(len(h) - 1):
#
# line1 = canvas.create_line(100, h[i], 500, h[j])
# line2 = canvas.create_line(100, h[i+1], 500, h[j+1])
# # lines = canvas.create_line(0,0,600,400)
# # balls = canvas.create_oval(200, 150, 230, 110, outline="gray", fill="gray", width=6)
# canvas.pack(fill=BOTH, expand=1)
# canvas.delete(line1)
# window.update()
# window.after()
# canvas.delete(lines)
# canvas.update()
# lines.destroy()
# i = w.create_line(xy, fill="red")
line = canvas.create_line(100, 200, 500, 200)
canvas.pack(fill=BOTH, expand=1)
window.after(1000, uptodate())
window.mainloop()