In: Computer Science
Python 3
Fix the code so i can make the window larger and the fields increase 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) 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("Peter") # 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() date = cal._date 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') # 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()
Below is the solution:
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").place(x=100, y=50) #set the position x and y tk.Label(window, text="Products failed").place(x=100, y=100) #set the position x and y tk.Label(window, text="Money Lost").place(x=100, y=150) #set the position x and y tk.Label(window, text="sold by").place(x=100, y=200) #set the position x and y tk.Label(window, text="Failed date").place(x=100, y=250) #set the position x and y # 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) barcode.place(x = 300, y = 50, width = 300, height = 25) #set the position x and y ans set the size width and height product.place(x = 300, y = 100, width = 300, height = 25) #set the position x and y ans set the size width and height money.place(x = 300, y = 150, width = 300, height = 25) #set the position x and y ans set the size width and height options = tk.StringVar(window) options.set("Peter") # default value soldData = tk.OptionMenu(window, options, "Peter", "John", "Mary", "Jonatan", "Steve") soldData.place(x = 300, y = 200, width = 300, height = 25) #set the position x and y ans set the size width and height cal = DateEntry(window, width=12, background='darkblue', foreground='white', borderwidth=2) cal.place(x = 300, y = 250, width = 300, height = 25) #set the position x and y ans set the size width and height def readValue(): excel_barcode = barcode.get() excel_product = product.get() excel_money = money.get() excel_sold = options.get() date = cal._date 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') # button to trigger actions button = tk.Button(text="SUBMIT", command=readValue) button.place(x = 300, y = 300, width = 100, height = 25) #set the position x and y ans set the size width and height button = tk.Button(text="CLEAR", command=cleardate) button.place(x = 450, y = 300, width = 100, height = 25) #set the position x and y ans set the size width and height window.geometry("750x400+200+200") #resize the window size with position from top 100 pixel and left 100 pixel window.resizable(0, 0) #Don't allow resizing in the x or y direction window.mainloop()
sample output:
Please upvote if you find the solution: