zoukankan      html  css  js  c++  java
  • Tk库的使用(1)

    #
    # To change this template, choose Tools | Templates
    # and open the template in the editor.
     
    # Sample code from Programing Ruby, page 248
    require 'tk'

    class Draw
      def do_press(x, y)
        @start_x = x
        @start_y = y
        @current_line = TkcLine.new(@canvas, x, y, x, y)
      end

      def do_motion(x, y)
        if @current_line
          @current_line.coords @start_x, @start_y, x, y
        end
      end

      def do_release(x, y)
        if @current_line
          @current_line.coords @start_x, @start_y, x, y
          @current_line.fill 'black'
          @current_line = nil
        end
      end

      def initialize(parent)
        @canvas = TkCanvas.new(parent)
        @canvas.pack
        @start_x = @start_y = 0
        @canvas.bind("1", lambda {|e| do_press(e.x, e.y)})
        @canvas.bind("B1-Motion",
                     lambda {|x, y| do_motion(x, y)}, "%x %y")
        @canvas.bind("ButtonRelease-1",
                     lambda {|x, y| do_release(x, y)},
                     "%x %y")
      end
    end

    root = TkRoot.new { title 'Canvas' }
    Draw.new(root)
    Tk.mainloop
  • 相关阅读:
    Director.js路由
    高程第二天
    插件
    Github学习
    高程第一天
    盒子居中显示
    锋利的jq第四天
    锋利的jq第三天
    锋利的jq第二天
    锋利的jq第一天
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2035866.html
Copyright © 2011-2022 走看看