All pastes #3837386 Raw Edit

Untitled

public unlisted python v1 · immutable
#3837386 ·published 2017-07-01 19:10 UTC
rendered paste body
from random import randrangefrom tkinter import *    class Angles:    def __init__(self, parent):        self.myParent = parent                self.handicap = 15        self.n_of_squares = 16 # Must be even because of center lines.        self.canvas = Canvas(root, bg='white', width=300, height=300)                self.degree = IntVar()        self.origin = IntVar()        self.correct = StringVar()        self.correct.set('0')        self.attempts = StringVar()        self.attempts.set('0')        self.surrender = StringVar()        self.surrender.set('0')        self.ent = StringVar()        self.new_measure()        self.draw_grid()        self.draw_arc()        self.estimate()        self.btn()        self.lbl()        self.packall()                self.myParent.mainloop()            def new_handicap(self):        try:            self.handicap = int(self.ent.get())            self.ent.set('')            self.canvas.delete(self.arc)            self.new_measure()            self.draw_arc()        except ValueError:            pass    def new_measure(self):        self.degree.set(randrange(self.handicap, 360, self.handicap))        self.origin.set(randrange(360))        #print(self.origin.get(), self.degree.get())    def wrong(self):        if abs(int(self.ent.get()) - self.degree.get()) <= self.handicap:            self.close = Label(self.myParent, text='Close.', foreground='red')            self.close.pack()        self.attempts.set(str(int(self.attempts.get()) + 1))    def right(self):        self.correct.set(str(int(self.correct.get()) + 1))        self.attempts.set(str(int(self.attempts.get()) + 1))        self.new_measure()        self.canvas.delete(self.arc)        self.draw_arc()    def giveup(self):        self.surrender.set(str(int(self.surrender.get()) + 1))        self.ent.set('')        self.new_measure()        self.canvas.delete(self.arc)        self.draw_arc()    def evaluate(self):        try:            self.close.destroy()        except AttributeError:            pass                try:            if int(self.ent.get()) == self.degree.get():                self.right()            else:                self.wrong()            self.ent.set('')        except ValueError:            #self.giveup()            pass        def draw_grid(self):        for i in range((self.n_of_squares - 1)):            i_pos = (i + 1) * (300 / self.n_of_squares)                self.canvas.create_line(i_pos, 0 , i_pos, 300, fill='silver')            self.canvas.create_line(0, i_pos, 300, i_pos, fill='silver')        center_color = '#62bdc6'                self.canvas.create_line(150, 0 , 150, 300, fill=center_color, width=1.5)        self.canvas.create_line(0, 150, 300, 150, fill=center_color, width=1.5)    def draw_arc(self):        coord = (50, 50, 250, 250)        self.arc = self.canvas.create_arc(coord, start=self.origin.get()-(self.degree.get()/2), extent=self.degree.get(), width=2, fill='white')        print(self.degree.get())    def lbl(self):        Label(self.myParent, textvariable=self.correct)        Label(self.myParent, textvariable=self.attempts)    def estimate(self):        self.entry = Entry(self.myParent, textvariable=self.ent)        self.entry.focus_set()            def btn(self):        Button(self.myParent,text='Evaluate',command=self.evaluate)        Button(self.myParent,text='New Handicap',command=self.new_handicap)        #Button(self.myParent,text='Give up',command=self.giveup)            def packall(self):        for child in self.myParent.winfo_children(): child.pack()root = Tk()root.title('Estimate angles')root.geometry('500x440') # 500x400ang = Angles(root)