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.cb tkIntVar
self.cb tkIntVar
self.cb tkIntVar
self.cb tkIntVar
self.cbset
self.cbset
self.cbset
self.cbset
#Create checkboxes
self.serviceLabel tkLabelselfserviceF, text"SERVICESChoose as many as needed bg"light green", fontImpact
self.cbVar tkCheckbuttonselfserviceF, text"Oil Change $ bg"light green", variable self.cb commandself.Clear
self.cbVar tkCheckbuttonselfserviceF, text"Radiator Flush $ bg"light green", variable self.cbcommandself.Clear
self.cbVar tkCheckbuttonselfserviceF, text"Inspection $ bg"light green", variable self.cb commandself.Clear
self.cbVar tkCheckbuttonselfserviceF, text"Tire Rotation $ bg"light green", variable self.cb commandself.Clear
self.serviceLabel.pack
self.cbVar.packside"left"
self.cbVar.packside"left"
self.cbVar.packside"left"
self.cbVar.packside"left"
#Variable for radio buttons
self.rb tkStringVar
self.rb tkIntVar
self.rbset
#Create radio buttons
self.methodLabel tkLabelselffeeF, text"SERVICE FEEChoose One bg"light blue", fontImpat "bold"
self.rbVar tkRadiobuttonselffeeF, text "Normal Service Fee $ bg"light blue", variableself.rb value commandself.onselect
self.rbVar tkRadiobuttonselffeeF, text "Express Service Fee $ bg"light blue", variableself.rb value commandself.onselect
self.rbVar tkRadiobuttonselffeeF, text "Weekend Service Fee $ bg"light blue", variableself.rb value commandself.onselect
self.methodLabel.pack
self.rbVar.packside"left"
self.rbVar.packside"left"
self.rbVar.packside"left"
#Below is the listbox
self.payLabel tkLabelselfpayF, text"Choose Method of Payment BelowIf other than cash fontImpact bg"light yellow"
self.listbox tkListboxselfpayF
#Populate the listbox
self.listbox.insert "Cash"
self.listbox.insert "Check"
self.listbox.insert "Visa"
self.listbox.insert "MasterCard"
self.payLabel.pack
self.listbox.pack
#Create action buttons
self.display tkButtonselfbuttonF, text"DISPLAY CHARGES", fg"white", fontArial "bold", "underline" bg"black", command self.Display
self.quit tkButtonselfbuttonF, text"QUIT", fg"white", fontArial "bold", "underline" bg"black", command self.mainWindow.destroy
self.clear tkButtonselfbuttonF, text"CLEAR", fg"white", fontArial "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
tkmainloop
def onselectself:
selectoption self.rbget
printfSelect option: selectoption
def Clearself: #Method called from the clear button
self.Entrydelete 'end'
self.Entrydelete 'end'
self.cbdeselect
self.cbdeselect
self.cbdeselect
self.cbdeselect
self.rbset
printSelection cleared"
self.listbox.delete 'end'
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
