Changer l’icone par défaut de la fenêtre Tkinter Python

Dans ce tutoriel nous allons découvrir différents méthodes pour changer l’icone par défaut de la fenêtre Tkinter Python.

  • root.iconbitmap()
  • root.tk.call()
  • root.iconphoto()

 
 

Exemple 1: En utilisant la méthode root.iconbitmap()

iconbitmap(bitmap) définit l’icône du fenêtre sur bitmap. Le bitmap doit être de type ico, mais pas de type png ou jpg, sinon, l’image ne s’affichera pas sous forme d’icône.

import tkinter as tk

root = tk.Tk()
root.geometry("200x200")

root.iconbitmap('C:\\Users\\Pc\\Desktop\\icon.ico')

root.mainloop()

Sortie:


 

Exemple 2: En utilisant la méthode root.tk.call()
import tkinter as tk

root = tk.Tk()
root.geometry("200x200")

root.tk.call(
	'wm', 
	'iconphoto', 
	root._w, 
	tk.PhotoImage(file='C:\\Users\\Pc\\Desktop\\icon.png')
)

root.mainloop()

Sortie:


 
 

Exemple 3: En utilisant la méthode root.iconphoto()
import tkinter as tk

root = tk.Tk()
root.geometry("200x200")

root.iconphoto(False, tk.PhotoImage(file='C:\\Users\\Pc\\Desktop\\icon.png'))

root.mainloop()

Sortie:


 

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *