Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 540591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:15:22+00:00 2026-05-13T10:15:22+00:00

Hello my StackOverflow friends. I have been doing wxPython tutorials and reading the documentation,

  • 0

Hello my StackOverflow friends. I have been doing wxPython tutorials and reading the documentation, so far I like it. I wanted to make a simple app first. What this app would do is send a command to a micro controller to turn a relay on or off.

I have a global variable to get the COM port to be used (Instead of hardcoding COM1 in for instance)

I can’t get that variable to be correctly updated. Here is the code:

#!/usr/bin/env python

import wx
from firmata import *

# Arduino(port, baudrate=115200)
#arduino = Arduino(comListenPort)
#arduino.pin_mode(7, firmata.OUTPUT)
comListenPort = 'Is not set'
getComPort = 'Not Set'

class ArduinoDemo(wx.Frame):
    def __init__(self, parent, id):
        # Main window creation
        wx.Frame.__init__(self, parent, id, 'Demonstration of Firmata', \
                          size = (300, 200))

        # Content
        mainPanel = wx.Panel(self)

        # Open Contact button creation
        relayOpen = wx.Button(mainPanel, label = 'Open Contact', \
                              pos = (25, 25), size = (120, 60))

        # Close Contact button creation
        relayClosed = wx.Button(mainPanel, label = 'Close Contact', \
                                pos = (150, 25), size = (120, 60))

        # Binds click event from relayOpen to openRelay
        self.Bind(wx.EVT_BUTTON, self.closeRelay, relayClosed)
        # Binds click event from relayClose to closeRelay
        self.Bind(wx.EVT_BUTTON, self.openRelay, relayOpen)

        # Get correct COM port
        getComPort = wx.TextEntryDialog(None, 'Enter COM Port', 'COM Port', '')
        if getComPort.ShowModal() == wx.ID_OK:
            comListenPort = getComPort.GetValue()
            # # Debug
            print getComPort.GetValue()
            print comListenPort
            # # /Debug


    def openRelay(self, event):
        #arduino.digital_write(7, firmata.HIGH)
        # # Debug
        print comListenPort # does not print correctly
        # # /Debug

    def closeRelay(self, event):
        #arduino.digital_write(7, firmata.LOW)
        # # Debug
        print getComPort # does not print correctly
        # # /Debug


if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = ArduinoDemo(parent = None, id = -1)
    frame.Show()
    app.MainLoop()

Now I assume that having a global variable for this would the best way to do it, but I am completely looking for suggestions and pointers in everything. To the point though, comListenPort does not get assigned the value of my TextEntryDialog box. I know this has to be the dumbest thing I am overlooking.

The two debug print statements getComPort.GetValue() and comListenPort both print the correct data. When I click either the relayOpen or relayClosed button, they say ‘is not set’ or ‘not set’ still. I hope someone can slap some sense into me, I am pretty dumbfounded (emphasis on DUMB)

Thanks again

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:15:22+00:00Added an answer on May 13, 2026 at 10:15 am

    I think that inside __init__ Python sees comListenPort as a local variable, not global.. You should declare it global before using it:

    global comListenPort
    comListenPort = getComPort.GetValue()
    

    Alternatively, you could store the value as an instance variable of ArduinoDemo:

    self.comListenPort = getComPort.GetValue()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 369k
  • Answers 369k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try this: SELECT avg(ListingPrice), avg(SellingPrice), count(ListingDate), MONTH(SellingDate) as month, YEAR(SellingDate)… May 14, 2026 at 6:18 pm
  • Editorial Team
    Editorial Team added an answer This is documented and correct: https://www.php.net/manual/en/language.operators.array.php The + operator appends… May 14, 2026 at 6:17 pm
  • Editorial Team
    Editorial Team added an answer .NET 4 gives us a Zip method but it is… May 14, 2026 at 6:17 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.