Portál AbcLinuxu, 6. května 2025 07:28
import Tkinter, tkMessageBox class Platno(): def __init__(self,master): p=Tkinter.Canvas(width=100, height=100) p.grid(column=0, row=0) p.bind("Button-1",self.funkce) self.souradnice=[] def funkce(self,event): self.souradnice.append([event.x,event.y]) print self.souradnice[-1][0],self.souradnice[-1][1] top=Tkinter.Tk() platno=Platno(top) tkMessageBox.showinfo("Info","Klikej a pak zmackni OK") top.mainloop()Dik za info
Řešení dotazu:
import Tkinter class InfoW(Tkinter.Toplevel): def __init__(self): Tkinter.Toplevel.__init__(self) self.title('Info Window') self.geometry('100x30+0+0') self.lab = Tkinter.Label(self, text='') self.lab.pack() class Platno(): def __init__(self,master): p=Tkinter.Canvas(width=100, height=100) p.grid(column=0, row=0) p.bind("Button-1",self.funkce) self.info = InfoW() def funkce(self,event=None): self.info.lab['text'] = 'X:{}, Y:{}'.format(event.x, event.y) top=Tkinter.Tk() platno=Platno(top) top.title('Sem Klikej') top.mainloop()
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.