如何使用外部方法制作动画?

2024-04-26 12:16:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在制作一个GUI,在我的def Makewindow()函数中,我制作了我想要的不同标签,但我也希望它们是可点击的。但是问题是,我想在单击不同的选项卡(如Display_iconSettings_icon)时设置Line_icon的动画。我只是希望它滑动到标签下面(在本例中,它是一个显示图像),反之亦然,设置图标

这是我的密码:

from tkinter import *  # Import the tkinter module (For the Graphical User Interface)
from PIL import ImageTk, Image  # PILLOW for image formatting

width = 1920
height = 1080
RootGeo = str(width) + "x" + str(height)  # Make a def for RootGeo so the Root geometry isn't hardcoded


def Display_Click(event):
    print("[DISPLAY_CLICK] [INFO] [DEBUG] Display_icon has been clicked.")


def Settings_click(event):
    print("[SETTINGS_CLICK] [INFO] [DEBUG] Settings_icon has been clicked.")


def PicDir(PictureName):
    __DIRECTORY__ = "C:\\Users\\Gotta\\PythonProjects\\AutoCam\\Icons\\"
    __PICTURE_DIRECTORY__ = __DIRECTORY__ + PictureName

    print("[PICDIR] [INFO] [DEBUG] Photo Directory: ", __PICTURE_DIRECTORY__)
    return __PICTURE_DIRECTORY__


def MakeWindow():
    # -----Root_Attributes-----

    Root = Tk()
    Root.geometry(RootGeo)
    Root.state("zoomed")

    # -----Root_Attributes, Root_Containers-----

    SETTINGS = Image.open(PicDir("Settings.png"))
    SETTINGS_RENDER = ImageTk.PhotoImage(SETTINGS)
    Settings_icon = Label(Root, image=SETTINGS_RENDER)

    Settings_icon.grid(column=0, row=0, padx=(5, 5), pady=(3, 0))
    Settings_icon.bind("<ButtonRelease>", Settings_click)

    DISPLAY = Image.open(PicDir("Display.png"))
    DISPLAY_RENDER = ImageTk.PhotoImage(DISPLAY)
    Display_icon = Label(Root, image=DISPLAY_RENDER)

    Display_icon.grid(column=1, row=0, padx=(0, 5), pady=(3, 0))
    Display_icon.bind("<ButtonRelease>", Settings_click)

    LINE = Image.open(PicDir("Line.png"))
    LINE_RENDER = ImageTk.PhotoImage(LINE)
    Line_icon = Label(Root, image=LINE_RENDER)

    Line_icon.grid(column=0, row=1)

    '''RUN COMMAND: py -3 tkinkertest.py'''
    # -----Root_Containers----- ### NOT WORKING ###

    Root.mainloop()


MakeWindow()

Tags: imagesettingsdefdisplaylinerootrenderdirectory