Window

Main content

This is a little more complex but still very easy. To start I personally like to make a file because this code is going to be used multiple times and I don’t like to keep typing. Ok, first you need to import my module and define an window object.

from kirons_py3_module import *

screen = Window.init()

Now when you run the code it will do nothing, because the window is hidden. You can disable this with screen.display.show()

from kirons_py3_module import *

screen = Window.init()

screen.display.show()

Now that’s done we also want to define our own width, height, title and of course we want to disable the ability to resize our screen.

from kirons_py3_module import *

display = Window.Display(800,600,"Window example",False,False) # the False values are for resizableX and resizableY
screen = Window.init()

screen.set_display(display)
screen.display.show()

And finally we want to keep our screen updating. And also I’ll explain the code here

from kirons_py3_module import * # Most important! load kirons_py3_module.

# Our screen data, params: width, height, title, resizableX, resizableY
display = Window.Display(800,600,"Window example",False,False)

screen = Window.init() # Just creating our screen

screen.set_display(display) # Set our screen data (display) to our screen (screen)
screen.display.show() # Displays our screen

# Keeps our screen updating
while True:
    screen.display.update()

Canvas

By using kirons_py3_module.Window.Display we also defined an Canvas, which currently has Canvas.canv and Canvas.draw_rect

Canvas.draw_rect(x1,y1,x2,y2,color,outline_color=None) very simple syntax actually, x1 and y1 are the top-left position of the rectangle, x2 and y2 are the bottom-right position. Color is an HEX color use my Colors module (https://kirons-py3-module.readthedocs.io/en/latest/colors.html#the-colors-only-very-basic-ones) to convert RGB to HEX or for some basic colors. outline_color isn’t needed, only for an line 1 pixel outside your rectangle.

Example project:

from kirons_py3_module import *

display = Window.Display(800,600,"Canvas example",False,False) # the False values are for resizableX and resizableY
screen = Window.init()

screen.set_display(display)
screen.display.show()

x = 10
speed = 2

while True:
    screen.canvas.draw_rect(0,0,800,600,Colors.Black)
    screen.canvas.draw_rect(x,10,x+50,60,Colors.Magenta)
    x += speed
    screen.display.update()