如何在 Python Tkinter 中一段时间后隐藏小组件?
Tkinter 是用于开发基于 GUI 的应用程序的标准 Python 库。我们可以使用 Tkinter 库创建游戏、工具和其他应用程序。为了开发基于 GUI 的应用程序,Tkinter 提供小组件。
有时,可能需要隐藏小组件一段时间。这可以通过使用 pack_forget() 方法来实现。当我们使用各种方法在窗口中打包小组件时,我们必须使用相同的方法来隐藏该小组件。
示例
# Import the required libraries
from tkinter import *
from PIL import Image, ImageTk
# Create an instance of tkinter frame or window
win=Tk()
# Set the size of the tkinter window
win.geometry("700x350")
# Create a canvas widget
canvas=Canvas(win, width=400, height=300)
canvas.pack()
# Add an image in the canvas widget
img=ImageTk.PhotoImage(file="baseball.png")
canvas.create_image(100, 150,image=img)
# Hide the image from the canvas after sometime
canvas.after(3000, canvas.pack_forget)
win.mainloop()输出
运行给定的代码将在 Canvas 小组件中显示一张图像,该图像将在一段时间后消失。

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP