Graphic module Tkinter I

13 1 0
                                        

here the fun begins, this capitole will be split into two parts


there are many ways how to set up graphic module tkinter, but for now i'll show you two ways:

1. this is the more simple way to do so and I'd be happier if you will learn the second way

 this is the more simple way to do so and I'd be happier if you will learn the second way

Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.

on the screen you can see our first command: canvas.create_line

2.

this is the harder and more used way to set up your tkinter

Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.

this is the harder and more used way to set up your tkinter.
if tried to google meaning of these lines individualy, you might find just lot of advanced explanations you wont rlly understand.

root - needed when we want to actually interact with our graphic (buttons, labels, configurations)

canvas willl be used to draw shapes

!!!root.mainloop()!! - must be at the bottom of code


Before we get any further we have to understand how does tkinter x-y axis works

in top left conrner we got the [0,0] coordinates, when we want to go down we will increase Y when we want to go to the right we will increase X

Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.

in top left conrner we got the [0,0] coordinates, when we want to go down we will increase Y 
when we want to go to the right we will increase X.
in program you can use variables as coordinates.

for now we will be using commands:
canvas.create_line
canvas.create_rectangle
canvas.create_oval

programers often says that when making rectangle or circle you should input into code firstly coordinates of left top conorner and than right bottom corner, but when you actually think about it you will find out that it doesnt rlly matter untill you chose two opposite corners
Rectangle:
for example these two rectangles are exactly the same:

canvas.create_rectangle(100, 80, 50, 20) - first number is X, second is Y - this gives us coordinates of the first corner, third number is X of the 2nd corner, fourth number is Y of the 2nd corner

canvas.create_rectangle(50, 20, 100, 80) 


oval:
making ovals is bit more difficult, basicaly we are still puting in code two opposite corners so we will create a "invisible box" our oval will be drawn into this box, sides of oval will be touching this box.

oval:making ovals is bit more difficult, basicaly we are still puting in code two opposite corners so we will create a "invisible box" our oval will be drawn into this box, sides of oval will be touching this box

Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.

to visualize it better i've created the invisible box as well.
So hight of our oval will be difference between the two Y coordinates.
In our code first Y is 50, second is 100 so the hight of our oval is going to be 100-50 = 50
the difference between two X's is gonna be width of our oval.

inside of the command  canvas.create_rectangle/oval we can insert few more attributes - width of lines, fill of shape, colour of lines, colour of outlines...
in next screenshot you can look at its syntax in code

if you were interested into more attributes like this, our beloved chat gpt made a brief summary for them:

Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.

if you were interested into more attributes like this, our beloved chat gpt made a brief summary for them:

if you were interested into more attributes like this, our beloved chat gpt made a brief summary for them:

Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.

:D, dont worry i dont expect anyone to memorize all of this:)

I reccomand, you to experiment a little, try these commands,
todays challange is: try to make a house in python and send it to our community discord server: https://discord.gg/DMZ8dZbKXr


Part two for tkinter graphic module is comming soon

Python for beginnersWhere stories live. Discover now