Skip to content

Instantly share code, notes, and snippets.

@ismdeep
Created October 11, 2020 02:16
Show Gist options
  • Save ismdeep/d9d58fd4a36af63bbaf4aa94fb55fc13 to your computer and use it in GitHub Desktop.
Save ismdeep/d9d58fd4a36af63bbaf4aa94fb55fc13 to your computer and use it in GitHub Desktop.
Python 画图例子
from tkinter import *
from random import randint
width_size = 800
height_size = 600
canvas = Canvas(width=width_size, height=height_size)
canvas.pack(expand=YES, fill=BOTH)
colors = ['red', 'green', 'black', 'yellow', 'blue', 'gray', 'pink', 'purple']
for i in range(400):
x0 = randint(1, width_size)
y0 = randint(1, height_size)
x1 = randint(1, width_size)
y1 = randint(1, height_size)
canvas.create_line(x0, y0, x1, y1, width=1, fill=colors[randint(0, len(colors) - 1)])
mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment