1

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

TERMINATOR
  • 1,180
  • 1
  • 11
  • 24
  • This should help: https://stackoverflow.com/questions/3221908/is-it-possible-to-get-widget-settings-in-tkinter – j_4321 Nov 23 '20 at 13:55

1 Answers1

3

Solution:

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

TERMINATOR
  • 1,180
  • 1
  • 11
  • 24