I am asking that if there are several buttons in a Tkinter window and out of them some buttons are FLAT and some buttons are RAISED. I want a function to know if the button is raised or flat.
please help
thanks in advance
I am asking that if there are several buttons in a Tkinter window and out of them some buttons are FLAT and some buttons are RAISED. I want a function to know if the button is raised or flat.
please help
thanks in advance
tkinter
buttons have a relief property that specifies if a button is SUNKEN, RAISED, GROOVE, and RIDGE.
This is how you should go about checking if a button is raised or flat:
import tkinter as tk
def RaisedOrFlat(buttonName):
button = buttonName
# check if the button is Raised
if button['relief']== "raised":
return 'raised'
# check if the button is flat
elif button['relief'] == "flat":
return 'flat'
#Creates the form
main = tk.Tk()
#creates the button
btn1 = tk.Button(main, text='Button 1', relief="raised")
btn1.pack()
#call the function
if RaisedOrFlat(btn1) == 'flat':
print('flat')
elif RaisedOrFlat(btn1) == 'raised':
print('raised')
main.mainloop()
Output:raised