2- |
Python Tkinter,
to display line |
|
|
|
|
- In this program, of tkinter Module to
display line
Using Visual studio 2019
Compiler, to compile Python project /
file
- Source Code:
Download this
Source Code at python file - (0.5
KB python file) download
|
 |
Continue
|
Python Code,
to display line | |
|
|
|
#1-line
from tkinter import *
master = Tk()
canvas_width = 80
canvas_height = 40
w = Canvas(master,
width=canvas_width,
height=canvas_height)
w.pack()
y = int(canvas_height / 2)
w.create_line(0, y, canvas_width, y,
fill="#476042")
mainloop() |
|
| | |
- Output:
|
| | |
|
|
|
3- |
Python Tkinter,
to display rectangle
|
|
|
|
|
- In this program, of tkinter Module to
display rectangle design
Using Visual
studio 2019 Compiler, to compile {ython project /
file
- Source Code:
Download
this Source Code at python file -
(0.45 KB Python file) download |
 |
Continue
|
Python Code,
to display rectangle | |
|
|
|
#2-Rectangle
from tkinter import *
master = Tk()
w = Canvas(master, width=200,
height=100)
w.pack()
w.create_rectangle(50, 20, 150, 80,
fill="#476042")
w.create_rectangle(65, 35, 135, 65,
fill="yellow")
w.create_line(0, 0, 50, 20, fill="#476042", width=3)
w.create_line(0, 100, 50, 80,
fill="#476042", width=3)
w.create_line(150,20, 200, 0,
fill="#476042", width=3)
w.create_line(150, 80, 200, 100,
fill="#476042", width=3)
mainloop() |
|
| | |
- Output :
|
| | |
|
|
|
4- |
Python Tkinter,
to display rectangle & text design |
|
|
|
|
- In this program, of tkinter Module to
display rectangle & text
design
Using Visual studio 2019 Compiler, to
compile Python project / file
- Source Code:
Download
this Source Code at python file -
(1.3 KB Python file) download |
 |
Continue
|
Python Code,
to display rectangle & text | |
|
|
|
#3-Rectangle
+ line
from tkinter import *
canvas_width = 200
canvas_height = 100
colours = ("#476042", "yellow")
box=[]
for ratio in ( 0.2, 0.35 ):
box.append( (canvas_width * ratio,
canvas_height * ratio,
canvas_width * (1 - ratio),
canvas_height * (1 - ratio) ) )
master = Tk()
w = Canvas(master,
width=canvas_width,
height=canvas_height)
w.pack()
for i in range(2):
w.create_rectangle(box[i][0],
box[i][1],box[i][2],box[i][3],
fill=colours[i])
w.create_line(0, 0, # origin of
canvas
box[0][0], box[0][1], # coordinates
of left upper corner of the
box[0]
fill=colours[0],
width=3)
w.create_line(0, canvas_height, # lower left
corner of canvas
box[0][0], box[0][3], # lower left
corner of box[0]
fill=colours[0],
width=3)
w.create_line(box[0][2],box[0][1], # right upper corner of box[0]
canvas_width, 0, # right upper corner of
canvas
fill=colours[0],
width=3)
w.create_line(box[0][2], box[0][3], # lower right corner pf
box[0]
canvas_width, canvas_height, # lower right
corner of canvas
fill=colours[0], width=3)
w.create_text(canvas_width / 2,
canvas_height / 2,
text="Python")
mainloop() |
|
| | |
- Output :
|
| | |
|
|
|
5- |
Python Tkinter,
to display circle |
|
|
|
|
- In this program, of tkinter Module to
display circle
Using Visual studio 2019
Compiler, to compile Python project /
file
- Source Code:
Download this
Source Code at python file -
(0.4 KB Python file) download
|
 |
Continue
|
Python Code,
to display circle | |
|
|
|
#4-circle-oval
from tkinter import *
canvas_width = 190
canvas_height =150
master = Tk()
w = Canvas(master,
width=canvas_width,
height=canvas_height)
w.pack()
w.create_oval(20,20,100,100)
mainloop() |
|
| | |
- Output:
|
| | |
|
|
|
6- |
Python Tkinter,
to draw |
|
|
|
|
- In this program, of tkinter Module to
draw
Using Visual studio 2019 Compiler, to
compile Python project / file
- Source Code:
Download this
Source Code at python file - (0.65
KB Python file) download
|
 |
Continue
|
Python Code,
to draw | |
|
|
|
#5-painting-drawing
from tkinter import *
canvas_width = 500
canvas_height = 150
def paint( event ):
python_green = "#476042"
x1, y1 = ( event.x - 1 ), ( event.y - 1 )
x2, y2 = ( event.x + 1 ), ( event.y + 1 )
w.create_oval( x1, y1, x2, y2, fill =
python_green )
master = Tk()
master.title( "Painting using
Ovals" )
w = Canvas(master,
width=canvas_width,
height=canvas_height)
w.pack(expand = YES, fill = BOTH)
w.bind( "<B1-Motion>", paint )
message = Label( master, text = "Press and
Drag the mouse to draw" )
message.pack( side = BOTTOM )
mainloop() |
|
| | |
- Output:
|
| | |
|
|
|
7- |
Python Tkinter,
to display triangle |
|
|
|
|
- In this program, of tkinter Module to
display triangle design
Using Visual
studio 2019 Compiler, to compile Python project /
file
- Source Code:
Download this
Source Code at python file - (0.38
KB Python file) download
|
 |
Continue
|
Python Code,
to display triangle | |
|
|
|
#6-triangle
from tkinter import *
canvas_width = 200
canvas_height =200
python_green = "#476042"
master = Tk()
w = Canvas(master,
width=canvas_width,
height=canvas_height)
w.pack()
points = [0,0,canvas_width,canvas_height/2,
0, canvas_height]
w.create_polygon(points,
outline=python_green,
fill='yellow', width=3)
mainloop()
|
|
| | |
- Output:
|
| | |
|
|
|
8- |
Python Tkinter,
Module - Etoile (Star) |
|
|
|
|
- In this program, of tkinter Module to
display Etoile design
Using Visual
studio 2019 Compiler, to compile Python project /
file
- Source Code:
Download this
Source Code at python file - (0.5
KB Python file) download |
 |
Continue
|
Python Code,
to display Etoile | |
|
|
|
#7.1-etoile
from tkinter import *
canvas_width = 200
canvas_height =200
python_green = "#476042"
master = Tk()
w = Canvas(master,
width=canvas_width,
height=canvas_height)
w.pack()
points = [100, 140, 110, 110, 140, 100, 110,
90, 100, 60, 90, 90, 60, 100, 90, 110]
w.create_polygon(points,
outline=python_green,
fill='yellow', width=3)
mainloop() |
|
| | |
- Output:
|
| | |
|
|
|
9- |
Python Tkinter,
Module - X Etoiles (Stars) |
|
|
|
|
- In this program, of tkinter Module to
display X Etoiles design
Using Visual studio
2019 Compiler, to compile Python project /
file
- Source Code:
Download this
Source Code at python file - (1
KB Python file) download |
 |
Continue
|
Python Code,
to display X Etoiles | |
|
|
|
#7.2 Etoiles
from tkinter import *
canvas_width = 400
canvas_height =400
python_green = "#476042"
def
polygon_star(canvas, x,y,p,t, outline=python_green, fill='yellow', width = 1):
points = []
for i in (1,-1):
points.extend((x, y + i*p))
points.extend((x + i*t, y + i*t))
points.extend((x + i*p, y))
points.extend((x + i*t, y - i * t))
print(points)
canvas.create_polygon(points,
outline=outline,
fill=fill, width=width)
master = Tk()
w = Canvas(master,
width=canvas_width,
height=canvas_height)
w.pack()
p = 50
t = 15
nsteps = 10
step_x = int(canvas_width / nsteps)
step_y = int(canvas_height /
nsteps)
for i in range(1, nsteps):
polygon_star(w,i*step_x,i*step_y,p,t,outline='red',fill='gold', width=3)
polygon_star(w,i*step_x,canvas_height -
i*step_y,p,t,outline='red',fill='gold', width=3)
mainloop() |
|
| | |
- Output:
|
Pic 1 |
 |
Pic
2 |
|
| | |
|
|
|
10- |
Python Tkinter,
to display image |
|
|
|
|
- In this program, of tkinter Module to
display image
Using Visual studio 2019
Compiler, to compile Python project /
file
- Source Code:
Download
this Source Code at python file -
(0.32 KB Python file) download
|
st-rafca.gif
|
img = PhotoImage(file="st-rafca.gif") | |
 |
Continue
|
Python Code,
to display image | |
|
|
|
#8-picture
st-rafca.gif
from tkinter import *
canvas_width = 300
canvas_height =300
master = Tk()
canvas = Canvas(master,
width=canvas_width,
height=canvas_height)
canvas.pack()
img = PhotoImage(file="st-rafca.gif")
canvas.create_image(100,80, anchor=NW,
image=img)
mainloop() |
|
| | |
- Output:
|
| | |
11
|
|
|
11- |
Python Tkinter,
to display table with cells(200x100) |
|
|
|
|
- In this program, of tkinter Module to
display table with cells(200x100)
Using
Visual studio 2019 Compiler, to compile Python
project / file
- Source Code:
Download this
Source Code at python file - (0.68
KB python file) download |
 |
Continue
|
Python Code,
to display table with cells | |
|
|
|
#9-table
from tkinter import *
def
checkered(canvas, line_distance):
# vertical lines at an interval of
"line_distance" pixel
for x in range(line_distance,canvas_width,line_distance):
canvas.create_line(x, 0, x,
canvas_height, fill="#476042")
# horizontal lines at an interval
of "line_distance" pixel
for y in range(line_distance,canvas_height,line_distance):
canvas.create_line(0, y, canvas_width,
y, fill="#476042")
master = Tk()
canvas_width = 200
canvas_height = 100
w = Canvas(master,
width=canvas_width,
height=canvas_height)
w.pack()
checkered(w,30)
mainloop() |
|
| | |
- Output:
|
| | |
|
|
|
12- |
Python Tkinter,
to display text & logo |
|
|
|
|
- In this program, of tkinter Module to
display text & logo
Using Visual studio
2019 Compiler, to compile Python project /
file
- Source Code:
Download this
Source Code at python file -
(0.45KB python file) download |
python_logo_small.gif logo = tk.PhotoImage(file="python_logo_small.gif") |
 |
Continue
|
Python Code,
to display text & logo | |
|
|
|
import tkinter as tk
root = tk.Tk()
logo = tk.PhotoImage(file="python_logo_small.gif")
w1 = tk.Label(root,
image=logo).pack(side="right")
explanation = """At present, only GIF and
PPM/PGM
formats are supported, but an interface
exists to allow additional image file
formats to be added
easily."""
w2 = tk.Label(root,
justify=tk.LEFT,
padx = 10,
text=explanation).pack(side="left")
root.mainloop() |
|
| | |
- Output:
|
| | |
|
|