1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | #source code : https://github.com/swt02026/PerlTkxCalculator/tree/master
use Tkx; $feet=""; Tkx::ttk__label(".l",-textvariable => \$feet); Tkx::grid(".l", -column => 5, -row => 2, -sticky => 'nwes'); Tkx::button(".submit", -text => "=", -command => sub { if(!($feet=~/.*[*\/+-\.]$/)) {$feet=eval($feet);} },); Tkx::pack(".submit"); ($row,$col)= (0,6); Tkx::grid( ".submit", -column => $col , -row => $row+1, -sticky => "nwes"); Tkx::button(".0", -text => "0", -command => sub { $feet=$feet."0"; },); Tkx::pack(".0"); ($row,$col)= (0,3); Tkx::grid( ".0", -column => $col , -row => $row+1, -sticky => "nwes"); Tkx::button(".dot", -text => ".", -command => sub { if(!($feet=~/.*[*\/+-\.]$/)&& length($feet)!=0) { $feet=$feet."\.";} },); Tkx::pack(".dot"); ($row,$col)= (0,4); Tkx::grid( ".dot", -column => $col , -row => $row+1, -sticky => "nwes"); Tkx::button(".+", -text => "+", -command => sub { $feet=($feet."+") if(!($feet=~/.*[*\/+-\.]$/)) ; },); Tkx::pack(".+"); ($row,$col)= (1,3); Tkx::grid( ".+", -column => $col , -row => $row+1, -sticky => "nwes"); Tkx::button(".-", -text => "-", -command => sub { $feet=($feet."-") if(!($feet=~/.*[*\/+-\.]$/)); },); Tkx::pack(".-"); ($row,$col)= (1,4); Tkx::grid( ".-", -column => $col , -row => $row+1, -sticky => "nwes"); Tkx::button(".div", -text => "\/", -command => sub { $feet=($feet."\/") if(!($feet=~/.*[*\/+-\.]$/)&& length($feet)!=0); },); Tkx::pack(".div"); ($row,$col)= (2,3); Tkx::grid( ".div", -column => $col , -row => $row+1, -sticky => "nwes"); Tkx::button(".*", -text => "*", -command => sub { $feet=($feet."*") if(!($feet=~/.*[*\/+-\.]$/)&& length($feet)!=0); },); Tkx::pack(".*"); ($row,$col)= (2,4); Tkx::grid( ".*", -column => $col , -row => $row+1, -sticky => "nwes"); Tkx::button(".1", -text => "1", -command => sub { $feet=$feet."1"; },); Tkx::pack(".1"); ($row,$col)= (0,0); Tkx::grid( ".1", -column => $col , -row => $row+1, -sticky => "nwes"); Tkx::button(".2", -text => "2", -command => sub { $feet=$feet."2"; },); Tkx::pack(".2"); ($row,$col)= (0,1); Tkx::grid( ".2", -column => $col , -row => $row+1, -sticky => "nwes"); Tkx::button(".3", -text => "3", -command => sub { $feet=$feet."3"; },); Tkx::pack(".3"); ($row,$col)= (0,2); Tkx::grid( ".3", -column => $col , -row => $row+1, -sticky => "nwes"); Tkx::button(".4", -text => "4", -command => sub { $feet=$feet."4"; },); Tkx::pack(".4"); ($row,$col)= (1,0); Tkx::grid( ".4", -column => $col , -row => $row+1, -sticky => "nwes"); Tkx::button(".5", -text => "5", -command => sub { $feet=$feet."5"; },); Tkx::pack(".5"); ($row,$col)= (1,1); Tkx::grid( ".5", -column => $col , -row => $row+1, -sticky => "nwes"); Tkx::button(".6", -text => "6", -command => sub { $feet=$feet."6"; },); Tkx::pack(".6"); ($row,$col)= (1,2); Tkx::grid( ".6", -column => $col , -row => $row+1, -sticky => "nwes"); Tkx::button(".7", -text => "7", -command => sub { $feet=$feet."7"; },); Tkx::pack(".7"); ($row,$col)= (2,0); Tkx::grid( ".7", -column => $col , -row => $row+1, -sticky => "nwes"); Tkx::button(".8", -text => "8", -command => sub { $feet=$feet."8"; },); Tkx::pack(".8"); ($row,$col)= (2,1); Tkx::grid( ".8", -column => $col , -row => $row+1, -sticky => "nwes"); Tkx::button(".9", -text => "9", -command => sub { $feet=$feet."9"; },); Tkx::pack(".9"); ($row,$col)= (2,2); Tkx::grid( ".9", -column => $col , -row => $row+1, -sticky => "nwes"); Tkx::MainLoop() |
Perl計算機,使用Tkx
on
0 意見:
張貼留言