Portál AbcLinuxu, 26. prosince 2025 03:30
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
ps.: misto "Button-1" ma byt samozrejme <"Button-1">, ale editor to nejak nechce vzit
Ř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.