I can't get double value vx and vy
-
I can't get double value vx and vy. My first full Python program. Version 2.7
# -*- coding: utf8 -*- from Tkinter import * root=Tk() root.geometry('300x500') root.title('Программа')
frame1=Frame(root,width=300,heigh=300,bg='green',bd=5)
frame2=Frame(root,width=200,heigh=300,bg='white',bd=5)tx1 = Text(frame2, font=('times',12),width=20,height=1,wrap=WORD)
tx2 = Text(frame2, font=('times',12),width=20,height=1,wrap=WORD)
tx3 = Text(frame2, font=('times',12),width=20,height=1,wrap=WORD)
tx4 = Text(frame2, font=('times',12),width=20,height=1,wrap=WORD)label1 = Label(frame2, text="Координата x в пикселях")
label2 = Label(frame2, text="Координата y в пикселях")
label3 = Label(frame2, text="vx")
label4 = Label(frame2, text="vy")label1.pack()
tx1.pack(expand=NO,fill=BOTH)
label2.pack()
tx2.pack(expand=NO,fill=BOTH)
label3.pack()
tx3.pack(expand=NO,fill=BOTH)
label4.pack()
tx4.pack(expand=NO,fill=BOTH)
frame1.pack()
frame2.pack()def getXY(event):
tx1.delete('1.0', END) tx2.delete('1.0', END) tx3.delete('1.0', END) tx4.delete('1.0', END) getx = event.x gety = event.y x = getx y = gety vx = x/300 + 4 vy = y/300 + 4 tx1.insert(1.0, getx) tx2.insert(1.0, gety) tx3.insert(1.0, vx) tx4.insert(1.0, vy)
frame1.bind('<Button-1>', getXY)
root.mainloop()
-
In pythonon2 when the whole thing is divided by a whole
/
The result will be a number. In order to get a fractional number, you need either a denominator or a float:x = 123 print x/300 + 4 # 4 print float(x)/300 + 4 # 4.41 print x/300.0 + 4 # 4.41
(sighs) http://ideone.com/Cxx3zp )