(input_data.txt) Item|Category|Price|Unit Butter|Dairy|2.99|lb Cheese|Dairy|4.99|lb Egg|Dairy|1.99|dozen Buttermilk|Dairy|2.99|lb Chocolate Milk|Dairy|2.00|Gallon Milk|Dairy|1.99|Gallon Yogurt nonfat|Dairy|2.99|lb Yogurt whole|Dairy|2.99|lb Apples|Fruit|3.99|lb Oranges|Fruit|2.99|lb Banana|Fruit|1.69|lb Grapes|Fruit|3.99|lb...
Question:
(input_data.txt)
Item|Category|Price|Unit Butter|Dairy|2.99|lb Cheese|Dairy|4.99|lb Egg|Dairy|1.99|dozen Buttermilk|Dairy|2.99|lb Chocolate Milk|Dairy|2.00|Gallon Milk|Dairy|1.99|Gallon Yogurt nonfat|Dairy|2.99|lb Yogurt whole|Dairy|2.99|lb Apples|Fruit|3.99|lb Oranges|Fruit|2.99|lb Banana|Fruit|1.69|lb Grapes|Fruit|3.99|lb Blueberry|Fruit|4.99|pint Strawberry|Fruit|3.87|lb Pineapple|Fruit|1.99|each Raisins|Fruit|3.99|lb Cauliflower|Vegetable|1.99|lb Brocolli|Vegetable|1.99|lb Spinach|Vegetable|1.99|packet Baby SpinachCauliflower|Vegetable|2.99|lb Beet|Vegetable|1.99|lb Bell Pepper|Vegetable|1.00|each Carrots|Vegetable|2.99|lb Potatoes|Vegetable|2.99|lb Onions|Vegetable|1.69|lb Tomato|Vegetable|2.99|lb Whole chicken organic|Poultry|4.99|lb Whole chicken|Poultry|2.99|lb Thigh chicken|Poultry|2.99|lb Breast chicken|Poultry|2.99|lb Chicken ground|Poultry|2.99|lb Turkey breast|Poultry|3.99|lb Beef Chuck|Meat|2.99|lb Beef Patties|Meat|2.99|lb Ham|Meat|2.99|lb Salmon|Seafood|5.99|lb Shrimp|Seafood|5.99|lb Tilapia|Seafood|2.99|lb
from tkinter import *
class MyFrame(Frame):
def __init__(self, root):
'''Constructor method'''
Frame.__init__(self, root) #Frame class initialization
self.read_data() # read data from input file and create lists of items per category
self.welcome() #start the application (first frame)
def read_data(self):
''' open input_data.txtx and read/parse data to create lists of items '''
print("reading data from input file")
# >>>>>>> ADD YOUR CODE HERE # open file, read lines, parse lines to get items and cetgories
# create category lists and add items to each list
# Example:
# self.Dairy = [] --> append all Dairy items to this list
def welcome(self):
'''1. Welcome window - refer spec file for details'''
self.clear_frame() # call clear_frame() to cleatr the current frame and remove widgets
# >>>>>>> ADD YOUR CODE HERE # Create your widgets (labels and buttons) in the order they appear on the frame (top to bottom) and use the .grid() layout format to place the widget on the frame
# Example: label1 = Label(self, text = 'Welcome').grid()
# add the following actions to Buttons:
# Exit button –> exit the program, command = exit_application
# List Categories button --> list existing categories, command = list_category
def clear_frame(self):
'''Clears the previous frame'''
for widget in self.winfo_children():
widget.destroy()
def exit_application(self):
'''Exits the program'''
root.destroy()
def list_category(self):
''' List all categories '''
self.clear_frame() # call clear_frame() to cleatr the current frame and remove widgets
# >>>>>>> ADD YOUR CODE HERE # for each category, create a button with the category's name and place the button on the frame using .grid()
# add an action to each button by calling the show_items(categoryList) method.
# Use the below example as a guide:
# for the Dairy button, command = lambda m=self.Dairy : self.show_items(m) --> where m = self.Dairy and show_items(m) is a method that takes a list containing all dairy items
def show_items(self, items_list):
''' Display all items '''
self.clear_frame()
# >>>>>>> ADD YOUR CODE HERE # for every item in the items_list, create a text label and place it on the frame using .grid()
#### main driver code -- DO NOT MODIFY -- ####
#create root window
root = Tk()
root.title('HWA5')
#create a myframe object and layout
f = MyFrame(root)
f.pack()
#call mainloop
root.mainloop()