Приветствую смотрящих!
Мне нужно построить шестиугольник. Пользователь должен ввести размер. Только вот что-то не работает формула
построения шестиугольника. Вот код:
from tkinter import *
import math
class App:
def __init__(self, main):
self.entry_1 = Entry(main, width=20)
self.b_draw = Button(main, width=15, text="Draw")
self.b_clear = Button(main, width=15,text="Clear")
self.b_quit = Button(main, width=15, text="Quit")
self.lbl_radius = Label(main,width=10, text="Enter radius:")
self.lbl_radius_1 = Label(main, width=20)
self.b_draw.grid(row=0, column=0)
self.b_clear.grid(row=2, column=0)
self.b_quit.grid(row=18, column=0)
self.lbl_radius.grid(row=4, column=0)
self.lbl_radius_1.grid(row=10, column=0)
self.entry_1.grid(row=5, column=0)
self.b_draw.bind("<Button-1>", self.poligon)
self.b_clear.bind("<Button-1>", self.canvas_clr)
self.b_quit.bind("<Button-1>", self.close)
def poligon(self,event):
radius = self.entry_1.get()
radius = int(radius)
n = 6
for i in range(1, n + 1):
x1 = 340 + int(radius * math.cos(2*math.pi*i)) // n
y1 = 250 + int(radius * math.sin(2*math.pi*i)) // n
x2 = 340 + int(radius * math.cos(2*math.pi*i)) // n
y2 = 250 + int(radius * math.sin(2*math.pi*i)) // n
canvas.create_line((x1, y1), (x2, y2), fill="blue")
def canvas_clr(self, event):
canvas.delete("all")
def close(self,event):
root.destroy()
root = Tk()
root.title("Bib")
canvas = Canvas(width=700, height=500, bg='yellow')
canvas.grid(row=0, column=1, rowspan=20)
app = App(root)
root.mainloop()