tk create_arc
tkinter - Python interface to Tcl/Tk
Code Example #1
#! /usr/bin/python3
# ============================================================
# Code found on the web
# Note: the original code had errors
# ============================================================
# graphics.py is built on tk. This code works with
# graphics.py 5.0 and allows you to access the underlying tk
# methods, for example, create_arc(...).
# ============================================================
import graphics as gr
import tkinter as tk # import tkinter for arc styles
def draw_arc_in_graphics_py():
print(f'graphics.py version {gr.__version__}')
print(f'Tkinter Tk version {tk.TkVersion}')
# ---- graphics window/canvas
win = gr.GraphWin('Arc Example', 400, 400)
win.setBackground('white')
# ---- define bounding box coordinates (x0, y0, x1, y1)
x0, y0 = 50, 50
x1, y1 = 350, 350
# ---- draw a simple arc
win.create_arc(x0, y0, x1, y1, start=0, extent=90,
style=tk.ARC, outline='blue', width=2)
# ---- draw a pieslice arc
win.create_arc(x0, y0, x1, y1, start=180, extent=120,
style=tk.PIESLICE, fill='red')
# ---- draw a chord arc
win.create_arc(x0, y0, x1, y1, start=270, extent=60,
style=tk.CHORD, outline='green', width=3)
# ---- wait to end program
win.getMouse()
win.close()
if __name__ == '__main__':
draw_arc_in_graphics_py()
Code Example #2
#! /usr/bin/python3
# ============================================================
# draw a half circle
# ============================================================
import graphics as gr
import tkinter as tk # import tkinter for arc styles
def draw_arc_in_graphics_py():
print(f'graphics.py version {gr.__version__}')
print(f'Tkinter Tk version {tk.TkVersion}')
# ---- graphics window/canvas
width = 400
height = 400
win = gr.GraphWin("Half Circle Example", width, height)
win.setBackground('white')
wintop = gr.Line(gr.Point(0,0),gr.Point(width-1,0))
wintop.setWidth(1)
wintop.setFill('black')
wintop.draw(win)
# ---- draw X,Y axes
xaxis = gr.Line(gr.Point(0,height/2),
gr.Point(width-1,height/2))
xaxis.setWidth(1)
xaxis.setFill('blue')
xaxis.draw(win)
yaxis = gr.Line(gr.Point(width/2,0),
gr.Point(width/2,height-1))
yaxis.setWidth(1)
yaxis.setFill('blue')
yaxis.draw(win)
# ---- define bounding box coordinates (x0, y0, x1, y1)
x0, y0 = 50, 50
x1, y1 = 350, 350
# ---- draw bounding box
l1 = gr.Line(gr.Point(x0,y0),gr.Point(x1,y0))
l1.setWidth(1)
l1.setFill('red')
l1.draw(win)
l2 = gr.Line(gr.Point(x1,y0),gr.Point(x1,y1))
l2.setWidth(1)
l2.setFill('red')
l2.draw(win)
l3 = gr.Line(gr.Point(x1,y1),gr.Point(x0,y1))
l3.setWidth(1)
l3.setFill('red')
l3.draw(win)
l4 = gr.Line(gr.Point(x0,y1),gr.Point(x0,y0))
l4.setWidth(1)
l4.setFill('red')
l4.draw(win)
# ---- draw a half circle
win.create_arc(x0, y0, x1, y1, start=-90, extent=180,
style=tk.ARC, outline='black', width=2)
# ---- wait to end program
win.getMouse()
win.close()
if __name__ == '__main__':
draw_arc_in_graphics_py()