Created
March 11, 2019 21:41
-
-
Save jerome-labidurie/6e0ed16b835606f2c028d77f1fe2672a to your computer and use it in GitHub Desktop.
une grille de boutons et appel de command avec argument
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# fenetre avec grille de boutons | |
# doc en francais : http://tkinter.fdex.eu/index.html | |
import tkinter as tk | |
root = tk.Tk() | |
root.resizable(False, False) | |
# affiche un chaine passée en paramètre | |
def pbouton(str): | |
print (str) | |
# rempli une grille 3x3 de boutons | |
for col in range(3): | |
for ln in range(3): | |
mytext = "%d-%d" % (col, ln) | |
tk.Button (root, text=mytext, command=lambda t=mytext: pbouton(t) ).grid(column=col, row=ln) | |
# lambda t=mytext: pbouton(t) : quand on clique sur le bouton, on appelle pbouton en lui passant mytext en paramètre | |
# bouton pour quitter, étalé sur 3 colonnes, et qui prend toute la place | |
tk.Button (root, text="Quit", command=root.destroy).grid(row=3, columnspan=3, sticky='ew') | |
root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment