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
  • 相关阅读:
    近期学习情况
    java连接数据库的两种方法总结
    近两个星期学习成果
    云笔记第一阶段总结
    圆面积
    C++计算器项目的初始部分
    C++视频课程
    A+B Format
    大一下学期的自我目标
    Kohana的请求流
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2035866.html
Copyright © 2011-2022 走看看