Question: Im designing a gui in python. Im using tkinter. I have a clear function but for some reason I can only get it to work

Im designing a gui in python. Im using tkinter. I have a clear function but for some reason I can only get it to work with my text boxes.
But Ive had trouble getting it to work with my radio buttons, checkboxes and list box. This is the code for them and my clear button and function.
#Variables for checkboxes
self.cb1= tk.IntVar()
self.cb2= tk.IntVar()
self.cb3= tk.IntVar()
self.cb4= tk.IntVar()
self.cb1.set(0)
self.cb2.set(0)
self.cb3.set(0)
self.cb4.set(0)
#Create checkboxes
self.serviceLabel = tk.Label(self.serviceF, text="SERVICES(Choose as many as needed)", bg="light green", font=("Impact",14))
self.cb1Var = tk.Checkbutton(self.serviceF, text="Oil Change - $30.00", bg="light green", variable = self.cb1, command=self.Clear)
self.cb2Var = tk.Checkbutton(self.serviceF, text="Radiator Flush - $40.00", bg="light green", variable = self.cb2,command=self.Clear )
self.cb3Var = tk.Checkbutton(self.serviceF, text="Inspection - $35.00", bg="light green", variable = self.cb3, command=self.Clear)
self.cb4Var = tk.Checkbutton(self.serviceF, text="Tire Rotation - $20.00", bg="light green", variable = self.cb4, command=self.Clear)
self.serviceLabel.pack()
self.cb1Var.pack(side="left")
self.cb2Var.pack(side="left")
self.cb3Var.pack(side="left")
self.cb4Var.pack(side="left")
#Variable for radio buttons
self.rb = tk.StringVar()
self.rb = tk.IntVar()
self.rb.set(0)
#Create radio buttons
self.methodLabel = tk.Label(self.feeF, text="SERVICE FEE(Choose One)", bg="light blue", font=("Impat",14, "bold"))
self.rb1Var = tk.Radiobutton(self.feeF, text ="Normal Service Fee - $15.00", bg="light blue", variable=self.rb, value=1, command=self.on_select)
self.rb2Var = tk.Radiobutton(self.feeF, text ="Express Service Fee - $25.00", bg="light blue", variable=self.rb, value=2, command=self.on_select)
self.rb3Var = tk.Radiobutton(self.feeF, text ="Weekend Service Fee - $30.00", bg="light blue", variable=self.rb, value=3, command=self.on_select)
self.methodLabel.pack()
self.rb1Var.pack(side="left")
self.rb2Var.pack(side="left")
self.rb3Var.pack(side="left")
#Below is the listbox
self.payLabel = tk.Label(self.payF, text="Choose Method of Payment Below(If other than cash)", font=("Impact",12), bg="light yellow")
self.listbox = tk.Listbox(self.payF)
#Populate the listbox
self.listbox.insert(0, "Cash")
self.listbox.insert(1, "Check")
self.listbox.insert(2, "Visa")
self.listbox.insert(3, "MasterCard")
self.payLabel.pack()
self.listbox.pack()
#Create action buttons
self.display = tk.Button(self.buttonF, text="DISPLAY CHARGES", fg="white", font=("Arial",15, "bold", "underline"), bg="black", command = self.Display)
self.quit = tk.Button(self.buttonF, text="QUIT", fg="white", font=("Arial",15, "bold", "underline"), bg="black", command = self.mainWindow.destroy)
self.clear = tk.Button(self.buttonF, text="CLEAR", fg="white", font=("Arial",15, "bold", "underline"), bg="black", command = self.Clear)
self.display.pack()
#(side="") must be top bottom left or right
self.quit.pack()
self.clear.pack()
#Start the main loop for the window
tk.mainloop()
def on_select(self):
select_option = self.rb.get()
print(f"Select option: {select_option}")
def Clear(self): #Method called from the clear button
self.Entry1.delete(0, 'end')
self.Entry2.delete(0, 'end')
self.cb1.deselect()
self.cb2.deselect()
self.cb3.deselect()
self.cb4.deselect()
self.rb.set("")
print("Selection cleared")
self.listbox.delete(0, 'end')

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!