When I run my current program, the triangle shape on this program is only moving once when I press the button. I want my triangle shape to be moving automatically one pixel per unit time, but I am not sure how to make this work.
So far, while doing this program, I still cannot figure out which bits of classes and definitions go where and what to do with such classes and definitions to make them work like what I intended to, as written above.
import tkinter as tk
from tkinter import PhotoImage
from tkinter import *
import time
counter = 0
running = False
class triangle():
def trianglemovedefine(move_x, move_y):
canvas.move (triangle3, move_x, move_y)
def trianglemove():
triangle.trianglemovedefine(1, 0)
def moveitboi(justmoveit):
def count():
if running:
global counter
justmoveit = lambda:triangle.trianglemove()
#My "per unit time" adjusted to per 1000 microseconds
justmoveit.after(1000, count)
counter += 1
count()
def Start(justmoveit):
global running
running=True
moveitboi(justmoveit)
root = tk.Tk()
root.geometry("960x600")
label_toptitle = tk.Label(root, text="Program Name", font=(None, 40),)
label_toptitle.grid(row=0, columnspan=3)
label_desc = tk.Label(root, image=pixel, compound="center", width=900, font=(None, 14),
padx=20, pady=10, text=description)
label_desc.grid(row=1, columnspan=3)
canvas = tk.Canvas(width=960, height=300, bg='white')
canvas.grid(row=2, column=0, columnspan=3)
for linecounter in range(49):
newtextbit = linecounter + 1
if (newtextbit + 3) % 4 == 0 and newtextbit != 49:
canvas.create_text((linecounter * 16 + 80), 90,
fill="darkblue",
font="Times 10 bold",
text=newtextbit)
if (newtextbit + 3) % 4 == 0:
canvas.create_line(((linecounter * 16 + 80)), 40, ((linecounter * 16 + 80)), 70,
width=1,
fill="black"
)
else:
canvas.create_line(((linecounter * 16 + 80)), 50, ((linecounter * 16 + 80)), 70,
width=1,
fill="black"
)
canvas.create_line(73, 70, 860, 70,
width=2,
fill="black"
)
#The Triangle
triangle3 = canvas.create_polygon(75, 25, 86, 25, 80, 40, fill ='red')
f1 = tk.Frame(root, width=70, height=30)
f1.grid(row=3, column=0, sticky='W')
button_record = tk.Button(f1,
text="Record",
compound="top",
command=lambda:triangle.trianglemove(),
)
button_record.pack(side='left', padx=140)
root.mainloop()