Question

In: Computer Science

Python 3 Fix the code and rovide the correct indentation Code: import tkinter as tk from...

Python 3

Fix the code and rovide the correct indentation

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)

#creating list for barcode
barcode_ls=[]
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()
if(barcode_ls.count(excel_barcode)>=3):
messagebox.showwarning("Error", "The product is already tested 3 times and it reached the limits")
return
else:
barcode_ls.append(excel_barcode)
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

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)
barcode_ls=[]

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)
    
    if(barcode_ls.count(excel_barcode)>=3):
        messagebox.showwarning("Error", "The product is already tested 3 times and it reached the limits")
        return
        
    barcode_ls.append(excel_barcode)


    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()


Related Solutions

Python 3 Calendar does not showing up Fix code: # required library import tkinter as tk...
Python 3 Calendar does not showing up Fix code: # 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 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) cal = DateEntry(window, width=12, year=2019,...
Convert from python 2 to 3 from Tkinter import * # the blueprint for a room...
Convert from python 2 to 3 from Tkinter import * # the blueprint for a room class Room(object): # the constructor def __init__(self,name,image): # rooms have a name, exits (e.g., south), exit locations (e.g., to the south is room n), # items (e.g., table), item descriptions (for each item), and grabbables (things that can # be taken and put into the inventory) self.name = name self.image = image self.exits = {} self.items = {} self.grabbables = [] # getters and...
fix this code in python and show me the output. do not change the code import...
fix this code in python and show me the output. do not change the code import random #variables and constants MAX_ROLLS = 5 MAX_DICE_VAL = 6 #declare a list of roll types ROLLS_TYPES = [ "Junk" , "Pair" , "3 of a kind" , "5 of a kind" ] #set this to the value MAX_ROLLS pdice = [0,0,0,0,0] cdice = [0,0,0,0,0] #set this to the value MAX_DICE_VAL pdice = [0,0,0,0,0,0] cdice = [0,0,0,0,0,0] #INPUT - get the dice rolls i...
Please fix all of the errors in this Python Code. import math """ A collection of...
Please fix all of the errors in this Python Code. import math """ A collection of methods for dealing with triangles specified by the length of three sides (a, b, c) If the sides cannot form a triangle,then return None for the value """ ## @TODO - add the errlog method and use wolf fencing to identify the errors in this code def validate_triangle(sides): """ This method should return True if and only if the sides form a valid triangle...
Python 3 Fix the code so if the user does not select a value in the...
Python 3 Fix the code so if the user does not select a value in the sold by field, it shows a warning message indicating "Choose one value" import tkinter as tk from tkcalendar import DateEntry from openpyxl import load_workbook 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) #...
Python 3 Fix the code so if the user enter the same bar code more than...
Python 3 Fix the code so if the user enter the same bar code more than three times, it shows a warning message indicating that the product was already tested 3 times and it reached the limits 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,...
Python 3 Fix the code so i can make the window larger or smaller and the...
Python 3 Fix the code so i can make the window larger or smaller and the fields adjusts everytime according to the window size import tkinter as tk from tkcalendar import DateEntry from openpyxl import load_workbook 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="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)...
Please enter flowchart. Thank you! from tkinter import * from tkinter.scrolledtext import ScrolledText #method to open...
Please enter flowchart. Thank you! from tkinter import * from tkinter.scrolledtext import ScrolledText #method to open file and load contents into text field def open_file(): #fetching file name from filenamevar StringVar filename=filenamevar.get() try: #opening file in read mode file=open(filename,'r') #reading text text=file.read() #replacing current text in textField to read text textField.replace("1.0",END,text) #closing file file.close() except: #displaying error message in textField textField.replace("1.0", END, 'File not found!') #method to save current contents of file into file mentioned in file name entry field...
Fix this broken code? # Get our input from the command line import sys string =...
Fix this broken code? # Get our input from the command line import sys string = sys.argv[1] # Your code goes here if string 'Bingo' print('Missed') else: print('Hit!')
please correct the error and fix this code: (i need this work and present 3 graphs):...
please correct the error and fix this code: (i need this work and present 3 graphs): Sampling_Rate = 0.00004; % which means one data point every 0.001 sec Total_Time = 0:Sampling_Rate:1; % An array for time from 0 to 1 sec with 0.01 sec increment Omega = 49.11; % in [rad/s] zeta=0.0542; %unitless Omega_d=49.03; % in [rad/s] Displacement_Amplitude = 6.009; % in [mm] Phase_Angle = 1.52; % in [rad] Total_No_of_Points = length(Total_Time); % equal to the number of points in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT