如何使箭头在Canvas图像上随机移动?

时间:2019-06-02 08:08:42

标签: python tkinter

我正在制作一个随机数发生器,如图所示。

import random
import time

root = Tk()
root.title("Random Picker V.2")
root.iconbitmap(r'Icon.ico')

canvas = Canvas(root, width=1080, height=720)
canvas.pack()
good = PhotoImage(file='mrwallpapers.png')
goodha = PhotoImage(file='Very good.png')
canvas.create_image(50, 10, image=good)
canvas.create_text(530, 70, fill='white', text='Random Picker V.2', font=("Arial", 40, "underline"))
canvas.create_text(530, 130, fill='white', text='Random Arrow Moves', font=("Arial", 26))
canvas.create_text(530, 700, fill='yellow', text='This was made by Che 1/10 2019', font=("Arial", 15))
item = canvas.create_text(534, 280, fill='white', text='0', font=("Arial", 35))
item1 = canvas.create_text(263, 280, fill='white', text='0', font=("Arial", 35))
item2 = canvas.create_text(800, 280, fill='white', text='0', font=("Arial", 35))
arrow = canvas.create_image(540, 200, image=goodha)

def login():
    random1 = random.randint(1, 36)
    random2 = random.randint(1, 36)
    random3 = random.randint(1, 36)
    canvas.itemconfig(item, text=random1)
    canvas.itemconfig(item1, text=random2)
    canvas.itemconfig(item2, text=random3)
def login1():
    random4 = random.randint(1, 45)
    random5 = random.randint(1, 45)
    random6 = random.randint(1, 45)
    canvas.itemconfig(item, text=random4)
    canvas.itemconfig(item1, text=random5)
    canvas.itemconfig(item2, text=random6)
def login2():
    choice = ['260', '-265']
    random10 = random.choices(choice)
    canvas.move(arrow, random10, 0)
def randomnumber():
    canvas.itemconfig(item, fill='blue')
    root.after(500, randomnumber)
    canvas.itemconfig(item, fill='red')
    root.after(500, randomnumber)

gifted = Button(root, font=("Arial", 25), text="Gifted Pick (36)", command=login)
gifted.place(rely=0.59, relx=0.37, relwidth=0.25, relheight=0.07)

normal = Button(root, font=("Arial", 22), text="Normal Pick (45)", command=login1)
normal.place(rely=0.69, relx=0.37, relwidth=0.25, relheight=0.07)

photo = PhotoImage(file='color.png')
spinm = Button(root, image=photo, fg='white', font=("Arial", 22), command=login2)
spinm.place(rely=0.59, relx=0.62, relwidth=0.05, relheight=0.17)

root.mainloop()

我希望画布图像(箭头)通过幻灯片动画随机地向左或向右或向中间移动。这可能吗,我该怎么做?因为它不适用于我执行的代码(登录2),所以它移出了框架,并且我还希望箭头随机向左或向右滑动,因为它是随机数生成器。

0 个答案:

没有答案