📄 menu2.tk
字号:
#!/usr/bin/wish# Let's start off with the basics needed to draw circles and squares.wm title . "Menubutton demonstration"wm iconname . "Menubutton demo"# Initial parameters to draw circles and squaresset x 50set y 50set sqsize 30# procedure to draw canvas objectsproc AddObject {type} { global x y sqsize sqsize fillc if {$type == "circle"} { .c create oval $x $y [expr $x+$sqsize] [expr $y+$sqsize] \ -tags item -fill $fillc } elseif {$type == "square"} { .c create rectangle $x $y [expr $x+$sqsize] [expr $y+$sqsize] \ -tags item -fill $fillc } incr x 10 incr y 10}# Next, we create a canvas with a frame, menu button and a dismiss button.# The Frame widget will hold the menu and dismiss buttons.# We pack all the elements to create the main user interface.# create the basic User Interface canvas, 2 menu buttons and a dismiss buttonset c [canvas .c -width 200 -height 200 -bd 2 -relief ridge]frame .f -bd 2menubutton .f.m1 -menu .f.m1.menu -text "Draw" -relief raised -underline 0 \ -direction leftbutton .f.exit -text "Dismiss" -command "exit"# manage the widgets using the grid geometry manager.pack .c -side top -fill both -expand yespack .f -side top -fill x -expand yespack .f.m1 .f.exit -side left -expand 1# Finally, we add a menu to the menu button.# We create a menu and add three entries to it: two command entries to draw circle# and square objects, and a cascade widget for fill color selection.set m .f.m1.menumenu $m -tearoff 0$m add command -label "Circle" -command "AddObject circle" -accelerator "Meta-c"bind . <Meta-c> "AddObject circle"$m add command -label "Square" -command "AddObject square" -accelerator "Meta-s"bind . <Meta-s> "AddObject square"$m add separator$m add cascade -label "Fill Color.." -menu .f.m1.cascadeset m .f.m1.cascademenu $m -tearoff 0$m add radio -label "Red" -background red -variable background -value red \ -command "set fillc red"$m add radio -label "Yellow" -background yellow -variable background \ -value yellow -command "set fillc yellow"$m add radio -label "Blue" -background blue -variable background -value blue \ -command "set fillc blue"$m add radio -label "White" -background white -variable background -value white \ -command "set fillc white"$m invoke 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -