mahesh chaluvadi
mahesh chaluvadi

Reputation: 33

How to add jpg image as icon to root window in tkinter

I'm using python 3 and tkinter. I want to place my own image as icon to root window in place of default tkinter icon. Please help me. I have tried this code but of no use.

# -*- coding: utf-8 -*-
"""
Created on Thu Jun 21 10:12:56 2018

@author: Mahesh
"""
from tkinter import *
from tkinter import font
from tkinter import ttk
root=Tk()

root.title("Test Panel")
root.geometry('1100x800-120+0')

root.iconbitmap("C:\Users\Alex\Desktop\Pythonmat\swam.jpg")

root.mainloop()

Upvotes: 0

Views: 1345

Answers (2)

nonamelowlife
nonamelowlife

Reputation: 23

I think you can only use ico files for this.

For example:

from tkinter import *
root = Tk()
root.iconbitmap(r'C:\Users\Alex\Desktop\Pythonmat\py.ico')
root.mainloop()

Upvotes: 0

user7111497
user7111497

Reputation:

Try to convert the image to .ico. The iconbitmap function does not support jpg. You can alternetively use the PIL library to convert the image and then use it.

Upvotes: 0

Related Questions