Anonymous
Прыгающий логотип DVD в Python Tkinter
Сообщение
Anonymous » 30 ноя 2024, 00:57
Я пытаюсь сделать прыгающий логотип DVD в tkinter, но не знаю, как это сделать, с мячом получается, логотип не двигается. Логотип
Код: Выделить всё
# 1) create main window
from tkinter import *
from PIL import ImageTk, Image
fen = Tk()
fen.title('AllTech - Bouncing ball')
fen.resizable(False, False)
# 2) create canvas and ball
WIDTH, HEIGHT = 400, 300
canvas = Canvas(fen, width=WIDTH, height=HEIGHT)
canvas.pack()
img = ImageTk.PhotoImage(Image.open("dvd.gif"))
# ball = canvas.create_oval(10, 10, 50, 50, fill='black')
# 3) move the ball
xspeed = yspeed = 3
frame = Frame(fen, width=600, height=400)
frame.pack()
frame.place(anchor='center', relx=0.5, rely=0.5)
label = Label(frame, image = img)
label.pack()
def moveBall():
global xspeed, yspeed
canvas.move(canvas, xspeed, yspeed)
(leftPos, topPos, rightPos, bottomPos) = canvas.coords(img)
if leftPos = WIDTH:
xspeed = -xspeed
if topPos = HEIGHT:
yspeed = -yspeed
img.after(30, moveBall)
canvas.after(30, moveBall)
fen.mainloop()
Я пробовал с рекламой мяча, работает, но не знаю почему, с логотипом не получается.
Подробнее здесь:
https://stackoverflow.com/questions/747 ... on-tkinter
1732917454
Anonymous
Я пытаюсь сделать прыгающий логотип DVD в tkinter, но не знаю, как это сделать, с мячом получается, логотип не двигается. Логотип [code]# 1) create main window from tkinter import * from PIL import ImageTk, Image fen = Tk() fen.title('AllTech - Bouncing ball') fen.resizable(False, False) # 2) create canvas and ball WIDTH, HEIGHT = 400, 300 canvas = Canvas(fen, width=WIDTH, height=HEIGHT) canvas.pack() img = ImageTk.PhotoImage(Image.open("dvd.gif")) # ball = canvas.create_oval(10, 10, 50, 50, fill='black') # 3) move the ball xspeed = yspeed = 3 frame = Frame(fen, width=600, height=400) frame.pack() frame.place(anchor='center', relx=0.5, rely=0.5) label = Label(frame, image = img) label.pack() def moveBall(): global xspeed, yspeed canvas.move(canvas, xspeed, yspeed) (leftPos, topPos, rightPos, bottomPos) = canvas.coords(img) if leftPos = WIDTH: xspeed = -xspeed if topPos = HEIGHT: yspeed = -yspeed img.after(30, moveBall) canvas.after(30, moveBall) fen.mainloop() [/code] Я пробовал с рекламой мяча, работает, но не знаю почему, с логотипом не получается. Подробнее здесь: [url]https://stackoverflow.com/questions/74717087/bouncing-dvd-logo-in-python-tkinter[/url]