Advertisement
Nikmosi

Untitled

Apr 10th, 2023
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. import tkinter
  2.  
  3. def destroy():
  4. destroy_object = [e1, e2, e3, e4, button, label1, label2, label3, label4, canvas]
  5. for object_name in destroy_object:
  6. object_name.destroy()
  7. e1.delete(0, 'end')
  8. e2.delete(0, 'end')
  9. e3.delete(0, 'end')
  10. e4.delete(0, 'end')
  11. prepare()
  12.  
  13. def draw():
  14. canvas.grid(row=4, column=0, columnspan=4)
  15. master.geometry("450x450")
  16. x1 = int(e1.get())
  17. y1 = int(e3.get())
  18. x2 = int(e2.get())
  19. y2 = int(e4.get())
  20. canvas.create_oval(x1, y1, x2, y2)
  21. master.bind("<KeyPress>", handle_keypress)
  22.  
  23.  
  24.  
  25.  
  26. master = tkinter.Tk()
  27. label = tkinter.Label(master)
  28. entry = tkinter.Entry(master)
  29. master.geometry("150x150")
  30. canvas = tkinter.Canvas(master, bg="white")
  31.  
  32. def handle_keypress(event):
  33. if event.keysym == "space":
  34. destroy()
  35.  
  36. canvas.bind("<KeyPress>", handle_keypress)
  37.  
  38. def prepare():
  39. global e1, e2, e3, e4, button, label1, label2, label3, label4
  40. label1 = tkinter.Label(text="X1")
  41. label1.grid(row=0, column=0)
  42. e1 = tkinter.Entry(master, width=5)
  43. e1.grid(row=0, column=1)
  44. label2 = tkinter.Label(text="X2")
  45. label2.grid(row=1, column=0)
  46. e2 = tkinter.Entry(master, width=5)
  47. e2.grid(row=1, column=1)
  48.  
  49. label3 = tkinter.Label(text="Y1")
  50. label3.grid(row=0, column=2)
  51. e3 = tkinter.Entry(master, width=5)
  52. e3.grid(row=0, column=3)
  53.  
  54. label4 = tkinter.Label(text="Y2")
  55. label4.grid(row=1, column=2)
  56. e4 = tkinter.Entry(master, width=5)
  57. e4.grid(row=1, column=3)
  58.  
  59. button = tkinter.Button(master, text="Создать Овал", command=draw)
  60. button.grid(row=3, column=0, columnspan=4)
  61. prepare()
  62.  
  63. master.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement