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

  • SEARCH
  • Home
  • 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 8872843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:19:05+00:00 2026-06-14T18:19:05+00:00

I am building a simple signal generator in Python based on the Pyo and

  • 0

I am building a simple signal generator in Python based on the Pyo and WX libraries.

I have ran through the simple tutorials for each and have successfully bound buttons in WX to WX functions. I am now trying to generate a simple sine wave(at 440 hz) for 1 second by pressing the button labeled “Oscillator 1”; however, when the main() function executes, the sine tone is played and while the button is displayed in the wx frame I am unable to retrigger the sine tone. Both of these symptoms are unwanted.

Why does the sine tone play immediately on program execution? Why does the firstOSC button seemingly not work?

import wx
from pyo import *
import time

pyoServer = Server().boot()  
pyoServer.start()

class MainWindow(wx.Frame):
    def __init__(self,parent,title):
        wx.Frame.__init__(self,parent,title=title, size = (640,640))
        self.CreateStatusBar() # A StatusBar in the bottom of the window        

        # Signal Generator controls
        oscillator = SoundOutput()
        firstOSC = wx.Button(self, wx.ID_YES,"Oscillator 1 " + str(oscillator.str_osc1State))
        self.Bind(wx.EVT_BUTTON, oscillator.OnOff1(440), firstOSC)

        #Menus
        filemenu = wx.Menu()
        menuExit = filemenu.Append(wx.ID_EXIT,"&Exit","Terminate the program")
        menuBar = wx.MenuBar()
        menuBar.Append(filemenu,"&File")
        self.SetMenuBar(menuBar)    
        self.Bind(wx.EVT_MENU, self.OnExit, menuExit)

        self.Show(True)
    def OnExit(self,e):
        self.Close(True)   


class SoundOutput(object):
    def __init__(self):
        self.osc1State = False
        self.str_osc1State = "Off"
        self.a = Sine(440, 0, 0.1)     
    def OnOff1(self, frequency):
        self.a.freq = frequency
        self.a.out()
        time.sleep(1)
        self.osc1State = True

def Main():
    app = wx.App(False)
    frame = MainWindow(None,"Signal Generator")
    app.MainLoop()
  • 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-06-14T18:19:06+00:00Added an answer on June 14, 2026 at 6:19 pm

    I solved this by investigating how WX handles events. As it turns out, for some reason calling a method in a nested or separate instance of a class caused the tone to play at runtime instead of on the event. I fixed this by making a method for the MainWindow class that serves as the binded event handler for firstOSC. This method then calls the requisite methods for the actual oscillator class.

    Here is the new code:

        # Signal Generator controls
        self.fOscillator = SoundOutput()
        self.fOscillatorstatus = False
        self.firstOSC = wx.Button(self, wx.ID_ANY,"Oscillator 1 On")
        self.firstOSC.Bind(wx.EVT_BUTTON, self.OnFirstOSC)
    
        def OnFirstOSC(self,e):
        if not self.fOscillatorstatus:
            self.fOscillator.OnOff1(440) 
            self.fOscillatorstatus = True
            self.firstOSC.SetLabel("Oscillator 1 Off")
        elif self.fOscillatorstatus:
            self.fOscillator.OnOff1(0)
            self.firstOSC.SetLabel("Oscillator 1 On")
            self.fOscillatorstatus = False
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently building a simple ecommerce site and have ran into an interesting problem.
I'm building a simple web-based RSS reader in Python, but I'm having trouble parsing
I'm building a simple availability calendar with PHP and MySQL. I have a table
I'm building simple query builder, and I have two questions: Is it possible to
I'm building a simple API using django-tastypie. The idea is I have two resources:
I'm building a simple chat server in java , where users can have private
I'm building simple game and I need to set game speed for each level.
Building a simple Python game of Rock, Paper, Scissors for learning purposes. I've read
Im building a simple game app, where you have to move a ball away
I'm building simple phonebook. Thus a have created a class Person: public class Person

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.