Advertisement
k1alo

Untitled

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