简体   繁体   中英

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()

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.

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()

By root window are we speaking of the Xorg root window? Excuse my complete ignorance of python and tkinter, but I am looking for a way to print clickable icons to the root window in X.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM