I got this sort of edgy scenario I would like to accomplish in my tinkter app. The way my tinkter app would work is: a user needs to enter in some text. Then select a radio button option. Once a user selects the radio button option some value would be calculated. Now here is the edge case. Basically if a user were to select a radio option without entering a value I would like to show an error message "you need to enter a value into the input box" below the input box.
Here is what my code looks like:
from tkinter import *
class GetInterfaceValues():
def __init__(self):
self.root = Tk()
self.totalValue = StringVar()
self.root.geometry('900x500')
self.RadioText = StringVar()
self.getPeg = Button(self.root, text='calculate kegs values', command=self.findPeg)
self.quarterlyTextString = 'Keg'
self.yearlyTextString = 'parKeg'
self.textInputBox = Text(self.root, relief=RIDGE, height=1, width=6, borderwidth=2)
self.frequencyText = Label(self.root, text="Frequency")
self.normalKegRadioButton = Radiobutton(self.root, text="normal Keg", variable=self.RadioText,
value=self.quarterlyTextString, command=self.selectedRadioButtonOption)
self.parRadioButton = Radiobutton(self.root, text="Par Kegs", variable=self.RadioText, value=self.yearlyTextString,
command=self.selectedRadioButtonOption)
self.clearButton = Button(self.root, text="Clear",command=self.clear)
self.textInputBox.pack()
self.normalKegRadioButton.pack()
self.parRadioButton.pack()
self.getPeg.pack()
self.clearButton.pack()
self.root.mainloop()
def selectedRadioButtonOption(self):
radioButtonFrequencyOption = self.RadioText.get()
if(radioButtonFrequencyOption == self.quarterlyTextString):
self.findPeg()
if(radioButtonFrequencyOption == self.yearlyTextString):
print(self.yearlyTextString)
def getTextInput(self):
result = self.textInputBox.get("1.0", "end")
results = result.upper()
results = results.rstrip()
results = int(results)
return results
def clear(self):
self.parRadioButton.deselect()
self.normalKegRadioButton.deselect()
self.textInputBox.delete("1.0", "end")
def findPeg(self):
userInput = self.getTextInput()
lab = userInput * 15
print(lab)
app = GetInterfaceValues()
app.mainloop()

def selectedRadioButtonOption. What is stopping you to add aelsecondition to display your message?