1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| import tkinter as tk
class menuPerso(tk.Menu):
def __init__(self,parent):
super().__init__(parent,tearoff=1)
self.parent=parent
self.add_command(label="Choisir",command=self.choisir)
self.parent.bind("<Button-3>",self.pop_up)
def pop_up(self,evt):
self.post(evt.x_root, evt.y_root)
def choisir(self):
self.cellule.index=20
self.can.itemconfigure(self.cellule.chiffre,text=20)
class Carre(object):
def __init__(self,canevas,index,x0,y0):
self.index=index
self.x0,self.y0=x0,y0
self.chiffre=canevas.create_text(x0,y0,text=index)
class Application(tk.Tk):
def __init__(self):
super().__init__()
self.can=tk.Canvas(self,width=200,height=200)
self.can.grid(row=0,column=0)
self.cellule=Carre(self.can,10,60,80)
menuPerso(self)
app=Application()
app.mainloop() |
Partager