Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使箭头在画布图像上随机移动?_Python_Tkinter - Fatal编程技术网

Python 如何使箭头在画布图像上随机移动?

Python 如何使箭头在画布图像上随机移动?,python,tkinter,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

我正在制作一个随机数发生器,就像图中的一样

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()

我希望画布图像(箭头)随幻灯片动画随机向左、向右或中间移动。这可能吗?我该怎么做?因为它不适用于我所做的代码(login2),所以它会移出帧,我还希望有一个箭头随机滑动到左右或中间,因为它是一个随机数生成器。

添加使用过的img文件您应该在
choice
中使用整数而不是字符串,并使用
random.choice(choice)
而不是
random.choices(选择)
。要设置滑动动画,您应该一次将箭头移动一个小偏移量,例如,如果随机选择260,则在每一步睡眠时间很短的情况下,将箭头移动26个十次。添加使用过的img文件您应该在
choice
中使用整数而不是字符串,并使用
random.choice(选择)
而不是
random.choices(choice)
。要设置滑动动画,您应该一次将箭头移动一个小偏移量,例如,如果随机选择260,则在每一步睡眠时间很短的情况下将箭头移动26个十次。