Row et column pour un bouton
Bonjour/Bonsoir.
J'ai un code me permettant de récupèrer la localisation d'un bouton dans une grille. En effet, je récupère row et column pour l'afficher.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| # coding: utf-8
from tkinter import *
import tkinter as tk
main = Tk()
main.title('CasioMaker by Tituya')
taille_x = 127
taille_y = 63
def mouse(event):
grid_info = event.widget.grid_info()
print("Ligne:", grid_info["row"], "Colonne:", grid_info["column"])
for ligne in range(taille_y):
for colonne in range(taille_x):
button = tk.Button(frame_b, borderwidth=1, background='white', width=2, height=1)
button['command'] = lambda button=button: button.configure(background = 'black')
button.grid(row=ligne, column=colonne)
main.bind("<Button-1>", mouse)
main.mainloop() |
Mais seulement, j'ai aussi des scrollbar ayant elles aussi des indications de row et column. Voila qui pose un probleme. En effet, dès que je clique sur une scrollbar, mon programme m'affiche sa position !
J'aimerais donc savoir comment faire pour ne pas prendre compte de ses valeurs.
Code de la scrollbar
Code:
1 2 3 4 5 6 7 8
| #Barre vertical
vsbar = Scrollbar(frame, orient=VERTICAL, command=can.yview)
vsbar.grid(row=0, column=1, sticky=NS)
can.configure(yscrollcommand=vsbar.set)
#Barre horizontal
hsbar = Scrollbar(frame, orient=HORIZONTAL, command=can.xview)
hsbar.grid(row=1, column=0, sticky=EW)
can.configure(xscrollcommand=hsbar.set) |
Cordialement