@YatinBayya/

Cereals

Tkinter

No description

fork
loading
Files
  • main.py
  • data.txt
  • nohup.out
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from  tkinter import Tk,simpledialog,messagebox

def database():
  with open('data.txt') as file:
    for line in file:
      line = line.rstrip('\n')
      cereal, calories = line.split('/')
      cereals[cereal]=calories
def store(brand,cals):
  with open('data.txt','a') as file:
    file.write('\n'+brand+'/'+cals)
root = Tk()
root.withdraw()

cereals={}
database()

while True:
  query = simpledialog.askstring('Cereal','What are you going to eat for breakfast today?')
  query=query.capitalize()
  if query in cereals:
    result = cereals[query]
    messagebox.showinfo('Answer','The Calories of '+query+' is '+result)
  else:
    information = simpledialog.askstring('Teach Me','I would like to know how many calories are in a box of'+query+"?")
    cereals[query] = information
    store(query,information)