Advertisement
Guest User

Untitled

a guest
Apr 17th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. from tkinter import *
  2. from math import *
  3. def setwindow(root):
  4. root.title('Окно программы')
  5. root.resizable(False, False)
  6. w = 800
  7. h = 600
  8. ws = root.winfo_screenwidth()
  9. wh = root.winfo_screenheight()
  10. x = int(ws / 2 - w / 2)
  11. y = int(wh / 2 - h / 2)
  12. root.geometry("{0}x{1}+{2}+{3}".format(w, h, x, y))
  13.  
  14. def equation():
  15. global a
  16. global b
  17. global c
  18. global result
  19. x1 = str(float(b.get() * -1) + float(sqrt(b.get() ** 2 - float(a.get() * c.get() * 4) / float(a.get() * 2))))
  20. x2 = str(float(b.get() * -1) - float(sqrt(b.get() ** 2 - float(a.get() * c.get() * 4) / float(a.get() * 2))))
  21. result.config(text="x1 = " + x1 + "; " + "x2 = " + x2)
  22.  
  23. root = Tk()
  24. setwindow(root)
  25.  
  26. label_main = Label(root, text='ax^2 + bx + c = 0', font='tahoma 20')
  27. a = Entry(root, font='Tahoma 16')
  28. c = Entry(root, font='Tahoma 16')
  29. result = Label(root, font='Tahoma 18')
  30. but = Button(root, text='Вычеслить корень уравнения ', font='Tahoma 20', command=equation)
  31. labela = Label(root, text='a', font='Tahoma 16')
  32. labelb = Label(root, text='b', font='Tahoma 16')
  33. labelc = Label(root, text='c', font='Tahoma 16')
  34.  
  35. label_main.place(relx=0.5, rely=0.01, anchor='n')
  36. a.place(relx=0.5, rely=0.1, anchor='n')
  37. b.place(relx=0.5, rely=0.2, anchor='n')
  38. c.place(relx=0.5, rely=0.3, anchor='n')
  39. labela.place(relx=0.3, rely=0.09, anchor='n')
  40. labelb.place(relx=0.3, rely=0.19, anchor='n')
  41. labelc.place(relx=0.3, rely=0.29, anchor='n')
  42. but.place(relx=0.5, rely=0.5, anchor='n')
  43. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement