canvas.tk

来自「《Beginning Linux Programming》书的配置实例源代码。」· TK 代码 · 共 43 行

TK
43
字号
#!/usr/bin/wish -f# First we create the canvas and then some objects to display on it.set c [canvas .c -width 400 -height 300 -relief sunken -bd 2]set image [image create photo -file caption.gif -width 500 -height 200]$c create image 150 150 -anchor center -image $image -tags item$c create text 150 150 -text " Image Object"  -fill white$c create text 10 10 -text " Move any Item \n using Mouse " -justify center \                     -anchor nw -tags item  -fill red$c create rectangle 200 10  250 40 -fill yellow -outline blue -tags itempack .c# Next, we bind the canvas so that we can operate on the items shown on it.# We'll define the itemDragStart and dragItem  procedures next.bind $c <1> "itemDragStart $c %x %y"bind $c <B1-Motion> "dragItem $c %x %y"# For the procedure's benefit, we need to define two global variables, lastX and lastY.global lastX lastY# event handler for the <1> eventproc itemDragStart {c x y} {    global lastX lastY    set lastX [$c canvasx $x]    set lastY [$c canvasy $y]}# event handler for the <B1-Motion> eventproc dragItem {c x y} {    global lastX lastY    set x [$c canvasx $x]    set y [$c canvasy $y]    $c move current [expr $x-$lastX] [expr $y-$lastY]    set lastX $x    set lastY $y}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?