Advertisement
k1alo

Untitled

Nov 24th, 2023 (edited)
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. import tkinter
  2. from tkinter import *
  3. import requests
  4.  
  5.  
  6. def klg():
  7.     api_url = 'https://api.calorieninjas.com/v1/nutrition?query='
  8.     query = "milk"
  9.     response = requests.get(api_url + query, headers={'X-Api-Key': '1CHQ8yp+m7+5BXHFUoUJ+A==ai2RrNSHUy8hHUT9'})
  10.     if response.status_code == requests.codes.ok:
  11.         label3["text"] = response.text[response.text.find("calories") + 10: response.text.find("serving_size_g") - 3] + " calories"
  12.         print(response.text[response.text.find("calories") + 10: response.text.find("serving_size_g") - 3] + " calories")
  13.     else:
  14.         print("Error:", response.status_code, response.text)
  15.  
  16.  
  17.  
  18.  
  19. root = Tk()
  20. root.geometry("600x400")
  21. root.maxsize(600, 400)
  22. root.title("Калорийность продукта")
  23.  
  24. root.config(bg='#696969')
  25.  
  26. label1 = Label(text="Калорийность продукта", font=('Arial', 25, 'bold'), pady=20, bg='#696969')
  27. label1.pack()
  28.  
  29. pole = Entry(font=('Arial', 15, 'bold'))
  30. pole.pack()
  31.  
  32. button = tkinter.Button(text="Найти", bg='#1E90FF', command=klg)
  33. button.pack()
  34.  
  35. label3 = Label(pady=20, bg='#696969', font=('Arial', 15, 'bold'))
  36. label3.pack()
  37.  
  38. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement