Skip to content

Instantly share code, notes, and snippets.

@jerome-labidurie
Created March 5, 2019 17:21
Show Gist options
  • Save jerome-labidurie/722732b8e47eba1d3b7479a5b7de7768 to your computer and use it in GitHub Desktop.
Save jerome-labidurie/722732b8e47eba1d3b7479a5b7de7768 to your computer and use it in GitHub Desktop.
un bouton avec une image en python tkinter
#!/usr/bin/env python3
# doc : http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html
import tkinter as tk
class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.create_widgets()
def create_widgets(self):
# chargement image (full-color)
self.imgMaison = tk.PhotoImage ( file="/usr/share/icons/nuoveXT2/32x32/actions/gohome.png" )
# creation bouton avec image
self.maison = tk.Button(self, image=self.imgMaison)
# ou alors ajoute image après
#self.maison["image"] = self.imgMaison
# la fonction a executer quand on clique
self.maison["command"] = self.ditMaison
# en haut
self.maison.pack(side="top")
# si on veut juste afficher l'image
#self.canvas = tk.Canvas(self,width=32, height=32)
#self.canvas.create_image(0, 0, image=self.imgMaison)
#self.canvas.pack()
# un bouton pour sortir
self.quit = tk.Button(self, text="QUIT", fg="red",
command=self.master.destroy)
self.quit.pack(side="bottom")
def ditMaison(self):
print("Maison")
root = tk.Tk()
app = Application(master=root)
app.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment