Skip to content
Advertisement

Tkinter – TTK – Button change state after click

how can i change the state of a button made with TTK in Python after i clicked it ? I want to disable the button START after i press it once and re-enable it after pressing STOP. I want this because my code creates a new duplicated thread everytime i press Start … so… i want to disable it… I used TTK instead of TK cause i saw it looks better but i cant seem to figure out how to use a global variable that just flips the state of that START button after i press it …

Example :

JavaScript

This is my entire script so you can run it yourself and see what i mean …

JavaScript

Advertisement

Answer

Why did you use the same variable for multiple widgets? It doesn’t work like that because a variable can only contain one value. If you want to change the button state later then you have to have separate variable names. Also you first have to create a button and then grid it. Not doing them in one line because you see grid returns none so that means you actually stored none in the variable instead of the widget class.

To change the state of button you do this btn.config(state=DISABLED OR NORMAL)

This should work:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement