本日练习


今日代码:

```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')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值