How to Create an Image Button in Python Using PIL

preview_player
Показать описание
It's very simple! In this tutorial, I walk through creating image buttons in python using Tkinter and PIL. You can make any image into a functionally button. You can also resize the image and place it anywhere you like.

I hope you guys find this tutorial useful. Feel free to like, comment, subscribe, and share this video. Thank you so much!

Steps:
1. Import all necessary libraries
2. Get an image you want to turn into a button
3. Put the image in the folder
5. Resize the image
6. Get the image using ImageTk.PhotoImage()
7. Configure the button and the command
8. Place the button

Code used in this video:

from tkinter import *
import tkinter as tk
from PIL import Image, ImageTk

def open_start_window():
start_window = Tk()

def gallery_page():
print("Subscribe to JameSparKing")

def exit_window():

# gallery_button = tk.Button(text='Open Gallery', bg='blue', fg='white', command=gallery_page)
# font_style = font.Font(family='Arial', size=15, weight='bold')
# gallery_button['font'] = font_style

gallery_button_picture = ImageTk.PhotoImage(resize_gallery_button)
image_gallery_button = Button(image=gallery_button_picture, command=gallery_page)

exit_button = tk.Button(text='Exit', command=exit_window)

open_start_window()
Рекомендации по теме