我正在制作一个GUI,并在我的def Makewindow()
函数中制作了我想要的不同标签,但我也希望它们可以被单击。但是,问题在于,当单击诸如Line_icon
或Display_icon
之类的其他选项卡时,我想使Settings_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()