Basic Tkinter

Support

Required licenses

EasyImage

Recommended images

Any image

Location

Tkinter samples/basic

Purpose

This sample program demonstrates how to:

  • Perform and rotate and scale an image.

  • Display the image using the Tkinter GUI framework.

The process steps are:

  • Load an image.

  • Convert the image from RGB to BGR.

  • Scale and rotate the image.

  • Display the image.

Code highlights

  1. Load an image.

    import eVision
    
    image_rgb = eVision.EImageC24()
    image_rgb.Load("path/to/your/image")
    
  2. Rotate the image.

Attention

The image must be converted from RGB to BGR to be properly displayed with Tkinter.

```c++
image_rgb = eVision.EImageC24(image_rgb.Width, image_rgb.Height)

eVision.EasyColor.ConvertRGBImageToBGR(self.image_rgb, self.image_bgr)
```
  1. Scale and rotate the image.

    image_scaled_rotated = eVision.EImageC24(image_rgb.Width, image_rgb.Height)
    
    eVision.EasyImage.ScaleRotate(image_bgr, image_bgr.Width / 2, image_bgr.Height / 2, image_bgr.Width / 2, image_bgr.Height / 2, scale, scale, eVision.Easy.FromDegrees(rotation), image_scaled_rotated, 4)
    
  2. Display the image.

Attention

Consider reading carefully the note concerning the lifetime of Tkinter variables in the source code of the sample as well as the Tkinter documentation (https://docs.python.org/3/library/tkinter.html#images).