Question

In: Computer Science

Python 3 Add a drop down menu (label tag "Working product: " option values: yes, no...

Python 3

Add a drop down menu (label tag "Working product: " option values: yes, no ) and it should be stored in the xlsx file

Code:

import tkinter as tk
from tkcalendar import DateEntry
from openpyxl import load_workbook
from tkinter import messagebox
from datetime import datetime


window = tk.Tk()
window.title("daily logs")
window.grid_columnconfigure(1,weight=1)
window.grid_rowconfigure(1,weight=1)

# labels
tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20)
tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20)
tk.Label(window, text="Money Lost").grid(row=2, sticky="W", pady=20, padx=20)
tk.Label(window, text="sold by").grid(row=3, sticky="W", pady=20, padx=20)
tk.Label(window, text="Failed date").grid(row=4, sticky="W", pady=20, padx=20)

# entries
barcode = tk.Entry(window)
product = tk.Entry(window)
money = tk.Entry(window)

# arraging
barcode.grid(row=0, column=1)
product.grid(row=1, column=1)
money.grid(row=2, column=1)

options = tk.StringVar(window)
options.set("Choose one value")  # default value
soldData = tk.OptionMenu(window, options, "Peter", "John", "Mary", "Jonatan", "Steve")
soldData.grid(row=3, column=1)
cal = DateEntry(window, width=12, background='darkblue', foreground='white', borderwidth=2)
cal.grid(row=4, column=1)

def readValue():
    excel_barcode = barcode.get()
    excel_product = product.get()
    excel_money = money.get()
    excel_sold = options.get()
    if excel_sold.strip() == 'Choose one value':
        messagebox.showwarning("Error", "Please select a value for sold by")
        return
    date = datetime.now()
    print(date)
    data = [excel_barcode, excel_product, excel_money, excel_sold, date]
    workbook = load_workbook("dailylog.xlsx")
    worksheet = workbook.worksheets[0]
    worksheet.append(data)
    workbook.save("dailylog.xlsx")
    cleardate()


def cleardate():
    barcode.delete(0, 'end')
    product.delete(0, 'end')
    money.delete(0, 'end')
    options.set("Choose one value")  # default value
    today = datetime.now()
    cal.set_date(today)


# button to trigger actions
button = tk.Button(text="SUBMIT", command=readValue).grid(row=5, pady=20, padx=20)
button = tk.Button(text="CLEAR", command=cleardate).grid(row=5, column=1, pady=20, padx=20)
window.geometry("500x400")
window.mainloop()

Solutions

Expert Solution

Below is the solution which is added the Label working product option menu Yes, No

code:

import tkinter as tk
from tkcalendar import DateEntry
from openpyxl import load_workbook
from tkinter import messagebox
from datetime import datetime


window = tk.Tk()
window.title("daily logs")
window.grid_columnconfigure(1,weight=1)
window.grid_rowconfigure(1,weight=1)

# labels
tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20)
tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20)
tk.Label(window, text="Money Lost").grid(row=2, sticky="W", pady=20, padx=20)
tk.Label(window, text="sold by").grid(row=3, sticky="W", pady=20, padx=20)
tk.Label(window, text="Failed date").grid(row=4, sticky="W", pady=20, padx=20)
tk.Label(window, text="Working product").grid(row=5, sticky="W", pady=20, padx=20) #Working product label

# entries
barcode = tk.Entry(window)
product = tk.Entry(window)
money = tk.Entry(window)

# arraging
barcode.grid(row=0, column=1)
product.grid(row=1, column=1)
money.grid(row=2, column=1)

options = tk.StringVar(window)
options.set("Choose one value")  # default value
soldData = tk.OptionMenu(window, options, "Peter", "John", "Mary", "Jonatan", "Steve")
soldData.grid(row=3, column=1)

cal = DateEntry(window, width=12, background='darkblue', foreground='white', borderwidth=2)
cal.grid(row=4, column=1)

#option menu for working product Yes/No
optionsWorkingProduct = tk.StringVar(window)
optionsWorkingProduct.set("Choose working product")  # default value
workingProduct = tk.OptionMenu(window, optionsWorkingProduct, "Yes", "No")
workingProduct.grid(row=5, column=1)


def readValue():
    excel_barcode = barcode.get()
    excel_product = product.get()
    excel_money = money.get()
    excel_sold = options.get()
    excel_workingProduct= optionsWorkingProduct.get()
    if excel_sold.strip() == 'Choose one value':
        messagebox.showwarning("Error", "Please select a value for sold by")
        return
    if excel_workingProduct.strip() == 'Choose working product': #check for the not selected working product
        messagebox.showwarning("Error", "Please select a value for working product")
        return
    date = datetime.now()
    print(date)
    data = [excel_barcode, excel_product, excel_money, excel_sold, date, excel_workingProduct]
    workbook = load_workbook("dailylog.xlsx")
    worksheet = workbook.worksheets[0]
    worksheet.append(data)
    workbook.save("dailylog.xlsx")
    cleardate()


def cleardate():
    barcode.delete(0, 'end')
    product.delete(0, 'end')
    money.delete(0, 'end')
    options.set("Choose one value")  # default value
    optionsWorkingProduct.set("Choose working product") # default value set to the working product
    today = datetime.now()
    cal.set_date(today)


# button to trigger actions
button = tk.Button(text="SUBMIT", command=readValue).grid(row=6, pady=20, padx=20)
button = tk.Button(text="CLEAR", command=cleardate).grid(row=6, column=1, pady=20, padx=20)
window.geometry("500x500")
window.mainloop()

sample output:

Find the Solution helpful please upvote


Related Solutions

Match the numbers below with the correct answer on the drop down menu. On answer can...
Match the numbers below with the correct answer on the drop down menu. On answer can be used more than once or not at all. 1. Stimulates liver for overall growth. 2. Inactive enzyme released by the liver for RAAS. 3.Zona of suprarenal glands where glucocorticoids are secreted. 4. Main hormones secreted by the zona fasciculata of suprarenal glands. 5. Released from suprarenal cortex and key player in RAAS. 6.Stimulates production of testosterone in males and post ovulation phase in...
Head to www.bls.gov and select Multifactor Productivity from the Subject drop-down menu. Scroll down and select...
Head to www.bls.gov and select Multifactor Productivity from the Subject drop-down menu. Scroll down and select the PDF version of the Multifactor productivity decreases 0.2% in 2016, first decline since 2009..   1. What has been the general trend for multi-factor productivity in the U.S. over the past 15 years? 2. What does this trend suggest has happened to production functions in the U.S.? 3. Assuming this change in productivity has happened to all firms, how will this change in productivity...
In React.js, how would you create a drop-down menu on a functional component such that selecting...
In React.js, how would you create a drop-down menu on a functional component such that selecting different options renders a different object? That is, depending on the option you select, you see a different HTML section in the browser.
In Python, write a calculator that will give the user the following menu options: 1) Add...
In Python, write a calculator that will give the user the following menu options: 1) Add 2) Subtract 3) Multiply 4) Divide 5) Exit Your program should continue asking until the user chooses 5. If user chooses to exit give a goodbye message. After the user selections options 1 - 4, prompt the user for two numbers. Perform the requested mathematical operation on those two numbers. Round the result to 1 decimal place. Example 1: Let's calculate! 1) Add 2)...
6. (Ignore the drop down option all the infomration needed is available) Evaluating Annie Hegg's Proposed...
6. (Ignore the drop down option all the infomration needed is available) Evaluating Annie Hegg's Proposed Investment in Atilier Industries Bonds Annie Hegg has been considering investing in the bonds of Atilier Industries. The bonds were issued 5 years ago at their $1,000 par value and have exactly 25 years remaining until they mature. They have an 8.0% coupon interest rate, are convertible into 50 shares of common stock, and can be called any time at $1,080.00. The bond is...
Click in cell B3, note that you can choose a product from the drop down list....
Click in cell B3, note that you can choose a product from the drop down list. This allows the company to select which product they wish to perform a CVP for. Ensure that calculations will return the correct answers regardless of which product is selected. In B4 use a formula to retrieve the Unit Sales Price from the Fixed Costs sheet for the product shown in B3. what is the formula to retrieve the price from two different spreadsheets(i mean...
Please show all work! 3. On the ballot, Illinois voters had the option to select "yes"...
Please show all work! 3. On the ballot, Illinois voters had the option to select "yes" or "No" when asked if the state’s minimum wage should be increased from $8.25 to $10 an hour by January 1, 2015. Before the actual voting date, a survey with a sample size of 50 found that 61.75% percent of respondents supported the minimum wage. A) Calculate the 95% and 90% confidence intervals for the minimum wage vote. B) After the election, the results...
python 3 We would like to add cursor-based APIs to the array-backed list API. To this...
python 3 We would like to add cursor-based APIs to the array-backed list API. To this end, we are including a cursor attribute, and two related methods. cursor_set will set the cursor to its argument index, and cursor_insert will insert its argument value into the list at the current cursor position and advance the cursor by 1. E.g, given an array-backed list l that contains the values [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], running the following...
Exercise #3 python Write a program that could evaluate the relationship between two values. User is...
Exercise #3 python Write a program that could evaluate the relationship between two values. User is to key in the two values, and it will be stored in variable, num1 and num2. The program will do a comparison between the two values. If num1 is greater than num2, a message will be display on screen to indicate that num1 is greater than num2. The program will also display appropriate messages when num2 is greater than num1; and num1 is equal...
Python 3 Fix this: The program is rewriting the product in excel everytime it gets executed...
Python 3 Fix this: The program is rewriting the product in excel everytime it gets executed i want to make a list and add new products everytime submit button its executed # required library import tkinter as tk from tkcalendar import DateEntry import xlsxwriter # frame window = tk.Tk() window.title("daily logs") #window.resizable(0,0) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window, text="Money Lost").grid(row=2, sticky="W", pady=20, padx=20) tk.Label(window, text="Failed date").grid(row=3, sticky="W", pady=20, padx=20) # entries...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT