Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import tkinter
- from tkinter import *
- import requests
- def klg():
- api_url = 'https://api.calorieninjas.com/v1/nutrition?query='
- query = "milk"
- response = requests.get(api_url + query, headers={'X-Api-Key': '1CHQ8yp+m7+5BXHFUoUJ+A==ai2RrNSHUy8hHUT9'})
- if response.status_code == requests.codes.ok:
- response = response.text
- response = json.loads(response)
- print(response["items"][0]["calories"])
- print(response["items"][0]["fat_total_g"])
- print(response["items"][0]["protein_g"])
- print(response["items"][0]["fat_saturated_g"])
- 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"])}'
- else:
- print("Error:", response.status_code, response.text)
- root = Tk()
- root.geometry("1920x1080")
- root.minsize(1920, 1080)
- root.title("Калорийность продукта")
- root.config(bg='#696969')
- label1 = Label(text="Калорийность продукта", font=('Arial', 25, 'bold'), pady=20, bg='#696969')
- label1.pack()
- pole = Entry(font=('Arial', 15, 'bold'))
- pole.pack()
- button = tkinter.Button(text="Найти", bg='#1E90FF', command=klg)
- button.pack()
- label3 = Label(pady=20, bg='#696969', font=('Arial', 15, 'bold'))
- label3.pack()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement