今日代码:
```c
class GUI(tk.Tk, object):
def init(self):
super(GUI, self).init()
# self.grab_set_global()
self.start_pos = [0, 0]
self.end_pos = [0, 0]
self.st = 0
self.ms = PyMouse()
self.c_mark_init = 0
self._build_gui()
self.bind(’’, self._MyEvent)
self.bind(’’, self._MouseMotion)
def _build_gui(self):
self.title('Jumper Broker')
w = int((BBOX_RIGHT - BBOX_LEFT)*IMG_RATIO)
h = int((BBOX_BOTTOM - BBOX_TOP)*IMG_RATIO)
self.geometry('{0}x{1}'.format(w,h))
self.canvas = tk.Canvas(self, width = w, height = h)
self.canvas.pack()
def _grab_image(self):
#grab and save the image
img = ImageGrab.grab(bbox=(BBOX_LEFT,BBOX_TOP, BBOX_RIGHT, BBOX_BOTTOM))
(w,h) = img.size
w = int(w * IMG_RATIO)
h = int(h * IMG_RATIO)
img2 = img.resize((w, h), Image.ANTIALIAS)
global g_tk_image
g_tk_image = ImageTk.PhotoImage(img2)
self.canvas.delete( 'all')
self.canvas.create_image(w/2, h/2, image = g_tk_image)
##create some grids
w_num = int(w/GRID_SIZE)
h_num = int(h/GRID_SIZE)
for i in range(w_num):
self.canvas.create_line(i*GRID_SIZE, 0, i*GRID_SIZE, h)
for j in range(h_num):
self.canvas.create_line(0, j*GRID_SIZE, w, j*GRID_SIZE)
def _Click(self):
dx = self.end_pos[0] - self.start_pos[0]
dy = self.end_pos[1] - self.start_pos[1]
len = math.sqrt(dx * dx + dy * dy)
t = len * TIME_COE
print(dx, dy, t)
self.ms.press(BBOX_LEFT, BBOX_TOP, BUTTON_ID)
self.after(int(t), self._over)
def _over(self):
self.ms.release(BBOX_LEFT, BBOX_TOP,BUTTON_ID)
self.focus_force()
def _DrawPos(self):
if self.st == 1:
x = self.start_pos[0]
y = self.start_pos[1]
elif self.st == 2:
x = self.end_pos[0]
y = self.end_pos[1]
self.canvas.create_oval(x-POS_SIZE, y-POS_SIZE, x+POS_SIZE, y+POS_SIZE, fill = 'yellow')