Demo entry 2719184

python

   

Submitted by anonymous on Sep 21, 2015 at 14:19
Language: Python 3. Code size: 4.1 kB.

#COUNTERS#
transparency=0.8
ans=('?')

#DEFINITIONS#
def Refresh():
    global Sca
    Select()
    main.attributes('-alpha', transparency)

def Select():
    global transparency
    global Sca
    transparency1 = (Sca.get())
    transparency=(transparency1/10)
    print (transparency)

#IMPORTS#
from tkinter import *
import math

main = Tk(); main.wm_resizable(0,0) 
main.title("Protractor")
main.attributes('-alpha', transparency)
main.geometry('500x600')
main.configure(background='blue')

#SLIDER#
def slider():
    global Sca
    slider = Tk()
    slider.geometry('200x50')
    main.title("Protractor Transparency")
    
    """SLIDER SUB SECTION"""

    Sca=Scale(slider, from_=1, to=10, orient=HORIZONTAL)
    Sca.pack(side=LEFT)
        
    RefreshMain=Button(slider, text='Apply', command=Refresh)
    RefreshMain.place(x=120, y=10)
    slider.mainloop()

angle='90'

def redA():
    global th
    th = (RED.get())
    print(th)

def blueA():
    global th2
    th2 = (BLUE.get())
    print(th2)

def mainfunction():
    global th
    global th2
    global ans
    redA()
    blueA()
    clear()
    oval()
    draw()
    angle=ans
    ANGLE.configure(text= ans)    


#WIDGETS#

Lab1=Label(main, text='Enter the angle of both traced lines into the boxes')
EntA=Entry(main, text='line 1', width=15)
EntB=Entry(main, text='line 2', width=15)


BLUE=Scale(main, from_=1, to=360, orient=HORIZONTAL, length=360, width=15, background='white', bd=0)

BLUE.place(x=1, y=543)

RED=Scale(main, from_=1, to=360, orient=HORIZONTAL, length=360, width=15, background='white', bd=0)

RED.place(x=1, y=500)

ANGLE=Button(main, text=angle, width=10, height=2, command=mainfunction)
ANGLE.place(x=390, y=520)


#####################replaceme########

def hello():
    print ('hello')    

#menu
menubar = Menu(main)
main['menu'] = menubar

fileMenu = Menu(menubar)
menubar.add_cascade(label="File", menu=fileMenu)
fileMenu.add_command(label="Hello", command=hello)

fileMenu = Menu(menubar)
menubar.add_cascade(label="Options", menu=fileMenu)
fileMenu.add_command(label="Transparency", command=slider)

fileMenu = Menu(menubar)
menubar.add_cascade(label="Help", menu=fileMenu)
fileMenu.add_command(label="Hello", command=hello)                   

    #CANVAS#

can1=Canvas(main, width=500, height=500)
can1.configure(background='white')

    #PACK AND PLACE#
Lab1.place(x=10, y=505)
EntA.place(x=90, y=40)
EntB.place(x=120, y=40)
can1.pack()  

    #CAN1 FUNCTION#

def oval():

    can1.create_oval(345,345,155,155, width=1, outline= 'blue')
can1.create_oval(345,345,155,155, width=1, outline= 'blue')

def clear():
    can1.delete(ALL)
                 
    #DRAW#

A=250
B=100

C=250
D=400

#radius is modifiable- changes length of lines
radius=200
#real radius is 95

#these theta variables are the key ones to modify to change line position
th=90
th2=360

#these are thier modified counterparts - DO NOT CHANGE
theta=th*(math.pi/180)
theta2=th2*(math.pi/180)

#Draw function needs to run on every slider change to update the lines.
#also needs to run in conjunction with a CLEAR CANVAS function (tbd) and a redraw of
# the circle -(clear does not discriminate individual objects).

def draw():
    global theta
    global theta2
    theta=th*(math.pi/180)
    theta2=th2*(math.pi/180)
    global A
    global B
    global C
    global D
    global ans
    
    A=0
    A=(math.sin(theta)*radius)
    A=(A+250)
    
    B=0
    B=(math.cos(theta)*radius)
    B=(250-B)

    C=0
    C=(math.sin(theta2)*radius)
    C=(C+250)

    D=0
    D=(math.cos(theta2)*radius)
    D=(250-D)

    can1.create_line(250, 250, A, B, fill="black")
    can1.create_line(250, 250, C, D, fill="black")

    if th2>th:
        ans=(th2-th)
    elif th>th2:
        ans=(th-th2)
    else:
        ans=0
        
        
    print(ans)
    A=250
    B=100

    C=250
    D=400
    
draw()


#MATH#


#RUN#

main.mainloop()

#slider.mainloop()

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).