Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arranged the buttons in 2 columns #44

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 19 additions & 27 deletions Shopping-list.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,44 +188,36 @@ def main():
combobox_filter.set("All") # Default filter is "All"
combobox_filter.bind("<<ComboboxSelected>>", lambda e: filter_items())

# Buttons with styles
# Buttons organized into two columns
button_add = tk.Button(frame, text="Add Item", font=("Arial", 12), bg="#b3ffb3", fg="black", command=add_item)
button_add.grid(row=5, column=0, columnspan=2, padx=5, pady=5, sticky="we")
button_add.grid(row=5, column=0, padx=5, pady=5, sticky="we")

button_edit = tk.Button(frame, text="Edit Item", font=("Arial", 12), bg="#ffcc99", fg="black", command=edit_item)
button_edit.grid(row=6, column=0, columnspan=2, padx=5, pady=5, sticky="we")
button_edit = tk.Button(frame, text="Edit Item", font=("Arial", 12), bg="#b3ffb3", fg="black", command=edit_item)
button_edit.grid(row=5, column=1, padx=5, pady=5, sticky="we")

button_remove = tk.Button(frame, text="Remove Item", font=("Arial", 12), bg="#ff9999", fg="black", command=remove_item)
button_remove.grid(row=7, column=0, columnspan=2, padx=5, pady=5, sticky="we")
button_remove = tk.Button(frame, text="Remove Item", font=("Arial", 12), bg="#ffb3b3", fg="black", command=remove_item)
button_remove.grid(row=6, column=0, padx=5, pady=5, sticky="we")

button_display = tk.Button(frame, text="Display List", font=("Arial", 12), bg="#cceeff", fg="black", command=display_list)
button_display.grid(row=8, column=0, columnspan=2, padx=5, pady=5, sticky="we")
button_display = tk.Button(frame, text="Display List", font=("Arial", 12), bg="#ffffb3", fg="black", command=lambda: display_list(combobox_filter.get()))
button_display.grid(row=6, column=1, padx=5, pady=5, sticky="we")

button_search = tk.Button(frame, text="Search Item", font=("Arial", 12), bg="#ccffcc", fg="black", command=search_item)
button_search.grid(row=9, column=0, columnspan=2, padx=5, pady=5, sticky="we")
button_total = tk.Button(frame, text="Total Cost", font=("Arial", 12), bg="#ffffb3", fg="black", command=calculate_total)
button_total.grid(row=7, column=0, padx=5, pady=5, sticky="we")

button_calculate = tk.Button(frame, text="Calculate Total Cost", font=("Arial", 12), bg="#ffff99", fg="black", command=calculate_total)
button_calculate.grid(row=10, column=0, columnspan=2, padx=5, pady=5, sticky="we")
button_search = tk.Button(frame, text="Search Item", font=("Arial", 12), bg="#ffffb3", fg="black", command=search_item)
button_search.grid(row=7, column=1, padx=5, pady=5, sticky="we")

button_clear = tk.Button(frame, text="Clear List", font=("Arial", 12), bg="#ffccff", fg="black", command=clear_list)
button_clear.grid(row=11, column=0, columnspan=2, padx=5, pady=5, sticky="we")
button_clear = tk.Button(frame, text="Clear List", font=("Arial", 12), bg="#ffb3b3", fg="black", command=clear_list)
button_clear.grid(row=8, column=0, columnspan=2, padx=5, pady=5, sticky="we") # Span across both columns

# Listbox to display the items
listbox_frame = tk.Frame(root)
listbox_frame.pack(padx=10, pady=10, fill='both', expand=True)
# Listbox to display shopping list
listbox = tk.Listbox(root, font=("Arial", 12), selectmode=tk.SINGLE, bg="#f9f9f9")
listbox.pack(padx=10, pady=10, fill='both', expand=True)

listbox = tk.Listbox(listbox_frame, font=("Arial", 12), width=50, height=10)
listbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
# Display initial list
display_list()

scrollbar = tk.Scrollbar(listbox_frame)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)

listbox.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=listbox.yview)

display_list() # Initial display of the shopping list
root.mainloop()

# Run the main function
if __name__ == "__main__":
main()