<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # Tcl/Tk 繪圖 > 原文: [http://zetcode.com/gui/tcltktutorial/drawing/](http://zetcode.com/gui/tcltktutorial/drawing/) 在 Tcl/Tk 教程的這一部分中,我們將做一些繪圖。 在`canvas`小部件上完成 Tk 的繪制。 畫布是 Tk 中圖形的高級工具。 它可以用于創建圖表,自定義窗口小部件或創建游戲。 ## 色彩 顏色是代表紅色,綠色和藍色(RGB)強度值的組合的對象。 ```tcl #!/usr/bin/wish # ZetCode Tcl Tk tutorial # # This program draws three # rectangles filled with different # colours. # # author: Jan Bodnar # last modified: March 2011 # website: www.zetcode.com canvas .can .can create rect 30 10 120 80 \ -outline #fb0 -fill #fb0 .can create rect 150 10 240 80 \ -outline #f50 -fill #f50 .can create rect 270 10 370 80 \ -outline #05f -fill #05f pack .can wm title . "Colours" wm geometry . 400x100+300+300 ``` 在代碼示例中,我們繪制了三個矩形,并用不同的顏色值填充了它們。 ```tcl canvas .can ``` 我們創建`canvas`小部件。 ```tcl .can create rect 30 10 120 80 \ -outline #fb0 -fill #fb0 ``` 使用`create`命令,我們在畫布上創建一個新的矩形項目。 前四個參數是兩個邊界點的 x,y 坐標:左上角和右下角。 使用`-outline`選項,我們可以控制矩形輪廓的顏色。 同樣,`-fill`選項為矩形的內部提供顏色。 ![Colours](https://img.kancloud.cn/63/ac/63ac5165e2db66f8febbe5475d5eec75_402x126.jpg) 圖:顏色 ## 形狀 我們可以在畫布上繪制各種形狀。 以下代碼示例將顯示其中的一些。 ```tcl #!/usr/bin/wish # ZetCode Tcl/Tk tutorial # # In this script, we draw basic # shapes on the canvas. # # author: Jan Bodnar # last modified: March 2011 # website: www.zetcode.com canvas .can .can create oval 10 10 80 80 -outline #777 \ -fill #777 .can create oval 110 10 210 80 -outline #777 \ -fill #777 .can create rect 230 10 290 60 -outline #777 \ -fill #777 .can create arc 30 200 90 100 -start 0 -extent 210 \ -outline #777 -fill #777 set points [ list 150 100 200 120 240 180 210 \ 200 150 150 100 200 ] .can create polygon $points -outline #777 \ -fill #777 pack .can wm title . "shapes" wm geometry . 330x220+300+300 ``` 我們在窗口上繪制五個不同的形狀:一個圓形,一個橢圓形,一個矩形,一個弧形和一個多邊形。 輪廓和內部以相同的灰色繪制。 ```tcl .can create oval 10 10 80 80 -outline #777 \ -fill #777 ``` `create oval`創建一個圓。 前四個參數是圓的邊界框坐標。 換句話說,它們是在其中繪制圓的框的左上和右下點的 x,y 坐標。 ```tcl .can create rect 230 10 290 60 -outline #777 \ -fill #777 ``` 我們創建一個矩形項目。 坐標還是要繪制的矩形的邊界框。 ```tcl .can create arc 30 200 90 100 -start 0 -extent 210 \ -outline #777 -fill #777 ``` 該代碼行創建了一條弧。 圓弧是圓的圓周的一部分。 我們提供邊界框。 `-start`選項是圓弧的起始角度。 `-extent`是角度大小。 ```tcl set points [ list 150 100 200 120 240 180 210 \ 200 150 150 100 200 ] .can create polygon $points -outline #777 \ -fill #777 ``` 創建一個多邊形。 它是具有多個角的形狀。 要在 Tk 中創建多邊形,我們向`create polygon`命令提供了多邊形坐標列表。 ![shapes](https://img.kancloud.cn/6e/c8/6ec8fcf3681d8381cf8a8f8c3b574b76_332x252.jpg) 圖:形狀 ## 繪制圖像 在以下示例中,我們將在畫布上創建一個圖像項。 ```tcl #!/usr/bin/wish # ZetCode Tcl/Tk tutorial # # This program draws an image # on the canvas widget. # # author: Jan Bodnar # last modified: March 2011 # website: www.zetcode.com package require Img image create photo img -file "tatras.jpg" set height [image height img] set width [image width img] canvas .can -height $height -width $width .can create image 0 0 -anchor nw -image img pack .can wm title . "High Tatras" wm geometry . +300+300 ``` 我們在畫布上顯示圖像。 ```tcl image create photo img -file "tatras.jpg" ``` 我們從位于當前工作目錄中的 JPG 圖像創建照片圖像。 ```tcl set height [image height img] set width [image width img] ``` 我們得到圖像的高度和寬度。 ```tcl canvas .can -height $height -width $width ``` 我們創建`canvas`小部件。 它考慮了圖像的大小。 ```tcl .can create image 0 0 -anchor nw -image img ``` 我們使用`create image`命令在畫布上創建一個圖像項。 為了顯示整個圖像,它固定在北部和西部。 `-image`選項提供要顯示的照片圖像。 ## 繪制文字 在最后一個示例中,我們將在窗口上繪制文本。 ```tcl #!/usr/bin/wish # ZetCode Tcl/Tk tutorial # # In this script, we draw text # on the window. # # author: Jan Bodnar # last modified: March 2011 # website: www.zetcode.com canvas .can .can create text 10 30 -anchor w -font Purisa \ -text "Most relationships seem so transitory" .can create text 10 60 -anchor w -font Purisa \ -text "They're good but not the permanent one" .can create text 10 110 -anchor w -font Purisa \ -text "Who doesn't long for someone to hold" .can create text 10 140 -anchor w -font Purisa \ -text "Who knows how to love without being told" .can create text 10 170 -anchor w -font Purisa \ -text "Somebody tell me why I'm on my own" .can create text 10 200 -anchor w -font Purisa \ -text "If there's a soulmate for everyone" pack .can wm title . "lyrics" wm geometry . 430x250+300+300 ``` 我們在窗口上畫一首歌的歌詞。 ```tcl .can create text 10 30 -anchor w -font Purisa \ -text "Most relationships seem so transitory" ``` 前兩個參數是文本中心點的 x,y 坐標。 如果我們將文本項錨定在西方,則文本將從該位置開始。 `-font`選項提供文本的字體,而-text 選項是要顯示的文本。 ![Drawing text](https://img.kancloud.cn/64/c2/64c2d6912ef3875141279a5892d53ce8_432x282.jpg) 圖:繪制文本 在 Tcl/Tk 教程的這一部分中,我們做了一些繪圖。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看