Advertisement
Guest User

Untitled

a guest
May 20th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. from tkinter import *
  2. lines = []
  3.  
  4. res = -1
  5. res_lines = []
  6.  
  7. SIZE = 3
  8. BSIZE = 5
  9.  
  10. def main():
  11. for i in range(len(lines)):
  12. canvas.create_line(lines[i][0], lines[i][1], lines[i][2], lines[i][3])
  13.  
  14. for a in range(len(lines) - 1):
  15. new_res = 1
  16. new_res_lines = [[lines[a][0], lines[a][1], lines[a][2], lines[a][3]]]
  17. for b in range(a, len(lines)):
  18. first_slope = (lines[a][3]- lines[a][1])/(lines[a][2]- lines[a][0])
  19. second_slope = (lines[b][3]- lines[b][1])/(lines[b][2]- lines[b][0])
  20. if first_slope == second_slope:
  21. new_res += 1
  22. new = []
  23. new.append(lines[b][0])
  24. new.append(lines[b][1])
  25. new.append(lines[b][2])
  26. new.append(lines[b][3])
  27. new_res_lines.append(new)
  28. global res
  29. if new_res > res:
  30. res = new_res
  31. global res_lines
  32. res_lines = new_res_lines
  33.  
  34. for i in range(len(res_lines)):
  35. canvas.create_line(res_lines[i][0], res_lines[i][1], res_lines[i][2], res_lines[i][3], fill="yellow")
  36.  
  37. def clear():
  38. canvas.delete("all")
  39. global lines
  40. lines = []
  41.  
  42. def add_point(x1, y1, x2, y2):
  43. canvas.create_oval(x1 - SIZE, y1 - SIZE, x1 + SIZE, y1 + SIZE, fill="red")
  44. canvas.create_oval(x2 - SIZE, y2 - SIZE, x2 + SIZE, y2 + SIZE, fill="red")
  45. canvas.create_line(x1, y1, x2, y2)
  46.  
  47. new = []
  48. new.append(x1)
  49. new.append(y1)
  50. new.append(x2)
  51. new.append(y2)
  52. global lines
  53. lines.append(new)
  54.  
  55. def add_from_but():
  56. x_1 = arg_x_1.get()
  57. y_1 = arg_y_1.get()
  58. x_2 = arg_x_2.get()
  59. y_2 = arg_y_2.get()
  60.  
  61. if 0 <= x_1 <= 1000 and 0 <= x_2 <= 1000 and 0 <= y_1 <= 1000 and 0 <= y_2 <= 1000:
  62. add_point(x_1, y_1, x_2, y_2)
  63. else:
  64. print("ошибка")
  65.  
  66.  
  67. root = Tk()
  68. root.title('Solution search')
  69. root["bg"] = "#edeef0"
  70.  
  71. root.geometry("1200x1000")
  72. root.resizable(height=False, width=False)
  73.  
  74. Label(root, font=('Ubuntu', 13), text='Введите новую точку').grid(row=0, column=0, columnspan=2)
  75.  
  76.  
  77. arg_x_1 = IntVar()
  78. arg_y_1 = IntVar()
  79.  
  80. EntryX_1 = Entry(root, textvariable=arg_x_1, width=5, font='Arial 16').grid(row=1, column=0)
  81. EntryY_1 = Entry(root, textvariable=arg_y_1, width=5, font='Arial 16').grid(row=1, column=1)
  82.  
  83. arg_x_2 = IntVar()
  84. arg_y_2 = IntVar()
  85.  
  86. EntryX_2 = Entry(root, textvariable=arg_x_2, width=5, font='Arial 16').grid(row=2, column=0)
  87. EntryY_2 = Entry(root, textvariable=arg_y_2, width=5, font='Arial 16').grid(row=2, column=1)
  88. add_button = Button(text="Добавить линию", command=add_from_but).grid(row=3, column=0, columnspan=2)
  89. search_button = Button(text="Произвести расчет", command=main).grid(row=4, column=0, columnspan=2)
  90. clean_button = Button(text="Очистить", command=clear).grid(row=16, column=0, columnspan=2)
  91.  
  92. canvas = Canvas(root, width=1000, height=1000, bg='grey')
  93. canvas.grid(row=0, column=2, rowspan=17)
  94.  
  95. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement