Tkinter เป็นไลบรารี Python มาตรฐานสำหรับการพัฒนาแอปพลิเคชันที่ใช้ GUI เราสามารถสร้างเกม เครื่องมือ และแอปพลิเคชั่นอื่น ๆ โดยใช้ไลบรารี 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 ซึ่งจะหายไปในบางครั้ง
