I'm new to programming and I'm trying to write a simple program to change the blink rate of an LED using a GUI.

When I try to run this on my RaspberryPi 2B running Raspbian, I get the following error that I don't understand:

Exception AttributeError: "'Button' object has no attribute '_hold_thread'" in Traceback (most recent call last)

and then

TypeError: __init__() got an unexpected keyword argument 'width'

To me this says that width is not a valid argument, but I ran another program on my Pi using width and it worked.

Code follows:

# This program will create an interactive GUI which can change an LED's blink rate

# Import necessary modules
from tkinter import *
from time import sleep
from gpiozero import *

# Set up GUI Window
mygui = Tk()
myfont = ('Times', 24, 'bold')
myfont2 = ('Times', 36, 'bold')
mygui.title('LED Controller')
counter = IntVar()
red_LED = LED(17)

while True:

    # Define usable functions
    def increase_speed():
        counter.set(counter.get() + 1)

    def decrease_speed():
        counter.set(counter.get() - 1)

    def end_program():

    # Create GUI labels
    label1 = Label(mygui, text='Increase Blink Speed', padx=15, pady=15, font=myfont)
    label1.grid(row=1, column=1, sticky=W)
    label2 = Label(mygui, text='Decrease Blink Speed', padx=15, pady=15, font=myfont)
    label2.grid(row=2, column=1, sticky=W)

    # Create GUI buttons
    button1 = Button(mygui, text='+', font=myfont2, command=increase_speed, fg='green', width=5)
    button1.grid(row=1, column=2, padx=10, pady=10, sticky=W)
    button2 = Button(mygui, text='-', font=myfont2, command=decrease_speed, fg='red', width=5)
    button2.grid(row=2, column=2, padx=10, pady=10, sticky=W)
    button3 = Button(mygui, text='Close Window', font=myfont, command=end_program, fg='black', bg='yellow', width=15)
    button3.grid(row=3, column=1, padx=10, pady=10, sticky=W)

    # Turn on LED

  • 1
    You should include context in error messages if you want help. I suspect your problem is Button in gpoizero is overwriting tkinter. Import * should be used with care. – Milliways Jan 2 at 21:23
  • Hi, thank you very much for the response. I clearly do want help, or else I wouldn't have made this post :) I'm not sure what you mean by including the context? What other information do you need? Import* could be the problem, that makes sense! – Clueless_User Jan 2 at 21:30
  • 1
    I assume Milliways means the full error msg, which includes where the error occurs, etc. – Dirk Jan 2 at 21:41
  • Ok understood, I will post that next time. Thanks Dirk! – Clueless_User Jan 2 at 21:43
  • 1
    As Milliways indicates the most likely error is that you import '*' from gpiozero. \this inludes a Button object which is then used instead of the tkinter version. Just import the LED oject from gpiozero – Dirk Jan 2 at 21:44

Milliways and Dirk are correct, import* was the problem. I should have realized that both GPIO Zero and Tkinter have a Button class, so one was overwriting the other and causing the error.

Thank you for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.