Reputation: 25
instead of using a ico file or blank icon in my tkinter application, i want the tkinter icon to be a 16x16 square with a certain color.
my current code:
import tkinter as tk
from tkinter import *
root = tk.Tk()
icon=PhotoImage(height=16, width=16)
icon.blank()
root.wm_iconphoto('True', icon) #New Tk 8.6 style
root.geometry('707x267')
root.title(" ")
root.mainloop()
how do i change the color of the icon?
Upvotes: 2
Views: 756
Reputation: 15098
You can create your own image with an image processing library, like PIL
. First install it:
pip install Pillow
Then create a new image with:
from PIL import Image, ImageTk
img = Image.new(mode='RGB',size=(16,16),color='red')
Now convert the image into tkinter understandable format with:
img_tk = ImageTk.PhotoImage(img)
Next, set the icon to be that new image:
root.wm_iconphoto('True', img_tk)
Upvotes: 1