April 11th, 2018, 08:24 AM
-
Circles & Arrows
This is merely a silly program I felt like posting.
Code:
# python3
import tkinter
# import tkinter.messagebox cannot set font in a messagebox. tkinter is ridiculous, I ridicule it.
# tkinter.messagebox.showinfo(master=root, title='Spam', message='Egg Information')
a = 600 # half height
b = 500 # half width
r = 100 # radius
style = (tkinter.PIESLICE, tkinter.CHORD, tkinter.ARC)
def callback(event):
global r
r = max(r - 5, 15)
print('clicked at', event.x, event.y)
canvas.create_arc(event.x - r, event.y - r, event.x + r, event.y + r,
start = 0, extent = 120, outline = 'blue', style = style[r % 3], width = 4)
canvas.create_line(b, a, event.x, event.y, arrow = tkinter.BOTH)
root = tkinter.Tk()
root.withdraw() # a little silly
root.title('Circles and arrows')
canvas=tkinter.Canvas(root, height = 2 * a, width = 2 * b)
canvas.pack()
canvas.bind("<Button>", callback)
tkinter.Label(root, # no reason to save it.
text = "Click within the `canvas' to choose center of another circle",
relief = tkinter.RIDGE,
font = ('times', 36)).pack(
ipady = 12,
ipadx = 36)
canvas.create_oval(b - r, a - r, b + r, a + r, fill = 'green', activefill = 'red')
root.deiconify()
root.mainloop()
[code]
Code tags[/code] are essential for python code and Makefiles!