1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
# coding:utf-8
from tkinter import *
from random import randrange
def draw_lines():
"""Drawing of a line in canvas1"""
global x1, x2, y1, y2, col
canvas1.create_line(x1, y1, x2, y2, width=2, fill=col)
# modification of coordinate for next line
y1, y2 = y1 + 10, y2 + 10
def change_col():
"""random modification of line color"""
global col
color = ["blue", "white", "green", "red", "orange", "purple", "cyan", "maroon", "yellow"]
i = randrange(len(color))
col = color[i]
# widget principal
draw_frame = Tk()
# widgets du widget principal
canvas1 = Canvas(draw_frame, bg="black", height=500, width=500)
canvas1.pack(side=LEFT)
button_quit = Button(draw_frame, text="Quit", command=draw_frame.quit)
button_quit.pack(side=BOTTOM)
button_draw_lines = Button(draw_frame, text="New line", command=draw_lines)
button_draw_lines.pack()
button_change_color = Button(draw_frame, text="Change color", command=change_col)
button_change_color.pack()
draw_frame.mainloop()
#draw_frame.destroy()
# __________ Main program _____________
# this variable will be use global
x1, y1, x2, y2 = 0, 0, 0, 0
col = "dark green" |
Partager