Get the text of a button widget
问题 I want to get the text from a button to compare it using an if-statement. Say I have this button: my_button = Button(self, text = 'hi') my_button.grid(row = 0, column = 0, sticky = W) And want to do something like this: my_text = my_button.text So that the following if-statement evaluates as True: if my_text == 'hi': # do something How can I do this in an easy way? 回答1: You can simply do: my_text = my_button['text'] Tkinter allows you to access any option of a widget this way ( height , width