Announcement

Collapse
No announcement yet.

Problem with "OnOffLedGui" code, project PythonCode_4D-CD-00155

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with "OnOffLedGui" code, project PythonCode_4D-CD-00155

    Hi,

    I'm new to using the IDLE program to use the GPIOs, and having copied the nice LED on/off project (PythonCode_4D-CD-00155 by Symon), am getting a load of error messages about nameErrors... I've copied it word for word with no typos, using the IDLE available via the LXterminal on the Armadillo.

    I updated and upgraded the 43T yesterday, so guess that is up-to-date. My Armadillo-43T is running IDLE under:

    Python 2.7.3 (default, Jun 22 2016, 03:14:32)
    [GCC 4.6.3] on linux2

    In Python "about" window it says "Python version: 2.7.3 Tk version: 8.5"

    Evidently, when I try to run it out of curiosity, knowing it will not work, the pop-up appears which reads: "There's an error in your program: invalid syntax"

    Below are the messages I get whilst writing the code:

    app = ABC(master = root)
    nameError: name 'ABC' is not defined

    app.master.title("GPIO sample")
    nameError: name 'app' is not defined

    B1 = Button(app, text = "turn on green LED", bg = "blue", activebackground = "blue", width = 15, borderwidth = 2, relief
    = SOLID, command = LED1)
    nameError: name 'app' is not defined

    B1.place(relx = 0.5, rely = 0.3, anchor = "c")
    nameError: name 'B1' is not defined

    B2 = Button(app, text = "turn on yellow LED", bg = "yellow", activebackground = "yellow", width = 15, borderwidth = 2,
    relief = SOLID, command = LED1)
    nameError: name 'app' is not defined

    B2.place(relx = 0.5, rely = 0.5, anchor = "c")
    nameError: name 'B2' is not defined

    quitButton = Button(app, text = "quit", bg = "white", activebackground = "white", width = 15, borderwidth = 2, relief =
    SOLID, command = exit)
    nameError: name 'app' is not defined

    quitButton.pack(side = Bottom)
    nameError: name 'quitbutton' is not defined

    app.mainloop()
    nameError: name 'app' is not defined

    Any help appreciated as I find this pretty difficult and after two years of teaching myself electronics, which I'm far more comfortable with, coding isn't my first love but know it's a necessary tool to avoid sometimes horribly large analog circuits, even if fun to put together, am getting fatigued with "guess the problem yourself in a new and very wide-ranging topic with multiple possibilities for the causes, maybe by attempt 100 or 1000 you might have figured it out and something will work..."

    Thank you.


  • #2
    ...I found the source of the above errors - not typing the code into a new IDLE window...

    Now the problem is that it works/runs okay, but the "pop-up" window/container ("GPIO sample") where the buttons should appear is blank, just a grey box with no buttons - what could be a reason for that? Thanks.

    Comment


    • #3
      Hi,

      Have you also updated your python package? Maybe a modification of the python library has occurred since the writing of the sample code.

      It might also be good to post Tkinter inquiries to forums such as python groups for more accurate feedback. Also maybe try some other python example such as these ones:
      https://www.youtube.com/watch?v=Bvq0LdBn0dY

      https://www.tutorialspoint.com/python/tk_button.htm

      Hope this helps,
      Last edited by Joseph Herrera; 7 February 2017, 04:38 PM. Reason: more info

      Comment


      • #4
        Hi Joseph,

        Thanks very much for your input. I think I've only updated and upgraded the Armadillo, but what you say about the Python library makes sense, as I seem to remember from starting to learn a bit of Python that some things work in one version but not in another, the tutorial book some-one graciously put on the Internet is good but understanding why some code isn't working is nervewracking as 2.7 and 3.4 seem different regarding some bits of code, but not others, and it's hard to know so much at once for an overwhelmed beginner, I'll look into that.

        Thanks for the links, they look helpful; I had a little look at Tkinter button yesterday evening, the "Hello World!" messagebox works, I will need to study quite a few things somewhat more. So far I've only attempted LED, blinking LED, and the on/off LED GUI, so all good things in time, especially understanding fault-finding/errors in Python.

        Many thanks

        Comment

        Working...
        X