- Fork this repository under your own account
- Clone the forked repository to your computer
- Commit your progress frequently and with descriptive commit messages
- All your answers and solutions should go in this repository
- You can use any resource online, but please work individually
- Don't just copy-paste your answers and solutions, use your own words instead.
The application is accepted if:
- The solution works according to specification [1p each]
- Has proper error handling where the specification says it [1p each]
- Has the correct loops, methods, filters [1p each]
- The code is clean, without unnecessary repetition, and with descriptive names [1p each]
- You commit frequently, after each task, with descriptive commit messages [1p]
- The solution follows styleguide [1p]
Define 'count_letter_in_string' function with parameters: 'string', 'letter' If 'string' is not string type: Set return value 0 and exit from function Define 'count' variable and set to 0 Iterate on the 'sting' characters If current letter (=the actual character in the string) equals to the searched 'letter': Increment 'count' by 1 Return the 'count' value
How can you create a graphical user interface and draw a rectangle on it in python? What are the tools needed for it? [2p]
Wee need to do the following steps:
-
First we need import the Python Tkinter drawing module: 'from tkinter import *'. This contains the graphical tools. Tkinter's image handling is limited (only some basic type allowed) so we need use PIL module if we would like to use other type of images (eg. jpg, png) in the canvas. We can use pil: 'from PIL import Image, ImageTk'
-
need to create a blank canvas. It has three steps: (1) creating a root variable for graphics, (2) define the canvas, (3) draw it (or create it)
root = Tk() my_canvas = Canvas(root, width=300, height=300, bg='white') my_canvas.pack()
-
now we can draw someting, eg. a rectancle: my_canvas.create_rectangle(x1, y1, x2, y2, fill='white', width='1')
- 'x1, y1' define the up left, 'x2, y2' define the down right corner of rectangle
- 'fill' the color of the rectangle
- 'width' is the border line width
-
need update the graphics to show:
my_canvas.update()
-
and finally we have to keep the canvas visible. Without this the canvas will shown only few moments:
my_canvas.mainloop()
V is the name os View module on MVC design pattern. It is responsible for the the graphical interface that the user can see on the screen. It contains graphical functions, elements (eg. canvas, button, display boxes, graphics and texts, etc.) It gets all the information from the Controller module, and typically not contains business logic calculation inside or only minimal which is neccessary for the graphical design.