Module 3: Intro to GUI


Slides
Video Lecture on Canvas()

Tipping Points

  • Graphical User Interface is one of the most important skills in coding.

    The basic concept of GUI is containing-components in a container. For example, a classroom contain desks, computers, and programmers, etc. A computer image contains a monitor, a keyboard, PC body, etc. A monitor image contains buttons, screen, and base, etc. Each programming language provides a set of graphic components.

    There are a number of GUI packages available in Python, e.g., Anaconda Python. One of them is Tk().
    The API of Tk is available here

    In Python Tk(), there are two large containers: Frame and Canvas.

    • Frame: used for business logic, which is detailed out here
    • Canvas: used for drawing, which is detailed out here
  • Canvas has the following methods (or functions):
    • create_line()
    • create_rectangle()
    • create_oval()
    • create_polygon()
    • create_arc()
    • create_image()

  • Any question?
    • Why Canvas() does not have parameters 700, 500, instead of width=700, height=500?
      Canvas (root, width=700, height=500)
                 
    • Why create_rectangle() does not have the parameter x1=200, y1=150, x2=450, y2=300, instead of simple parameter list 200,150, 450, 300?
      create_rectangle(200,150, 450, 300, fill="#476042")
                 
    • Answer is on the right side. Let's click below to go!