Python Forum
[WxPython] Adding a Window to a Button wxPython
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[WxPython] Adding a Window to a Button wxPython
#1
Hey Guys, I'm new to Python Programming and have a major doubt about adding a window to a button inside the GUI. Could any of you guide me how and where I can add a window to a button? I'm a little unsure about the coding aspect as well. Here is the Current Code I'm using:
import wx
 
########################################################################
class MyForm(wx.Frame):
 
    #----------------------------------------------------------------------
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, "Audiometer")
        panel = wx.Panel(self, wx.ID_ANY,size=(1000,600))
        self.SetBackgroundColour((255,255,255))#2nd input change - ShanksD
        self.Centre()#Change -ShanksD
        self.Show()#Change -ShanksD

        
        #self.buttonOne.SetPosition((20, 20))
        #self.buttonTwo.SetPosition((40, 40))
        #self.buttonThree.SetPosition((60, 60))
        #self.buttonFour.SetPosition((80, 80))
        #self.buttonFive.SetPosition((100, 100))
        #self.buttonSix.SetPosition((120, 120))
        #self.buttonSeven.SetPosition((140, 140))
 
        sizer = wx.BoxSizer(wx.VERTICAL)
        buttonOne = wx.Button(panel, label="Frequency", name="Frequency")
        buttonTwo = wx.Button(panel, label="Volume", name="Volume")
        buttonThree = wx.Button(panel, label="Pulse Tone", name="Pulse Tone")
        buttonFour = wx.Button(panel, label="Mask", name="Mask")
        buttonFive = wx.Button(panel, label="Air Bone", name="Air Bone")
        buttonSix = wx.Button(panel, label="Test Select", name="Test Select")
        buttonSeven = wx.Button(panel, label="INT", name="INT")
                              
        buttons = [buttonOne, buttonTwo, buttonThree,buttonFour, buttonFive,buttonSix,buttonSeven]
 
        for button in buttons:
            self.buildButtons(button, sizer)
 
        panel.SetSizer(sizer)
 
    #----------------------------------------------------------------------
    def buildButtons(self, btn, sizer):
        """"""
        btn.Bind(wx.EVT_BUTTON, self.onButton)
        sizer.Add(btn, 10, wx.ALL,37 )#Do not Change the VA=alue
 
    #----------------------------------------------------------------------
    def onButton(self, event):
        """
        This method is fired when its corresponding button is pressed
        """
        button = event.GetEventObject()
        print ("The button you pressed was labeled  ") + button.GetLabel()
        print ("The button's name is ") + button.GetName()
 
        button_id = event.GetId()
        button_by_id = self.FindWindowById(button_id)
        print ("The button you pressed was labeled: ") + button_by_id.GetLabel()
        print ("The button's name is ") + button_by_id.GetName()
 
#----------------------------------------------------------------------
# Run the program
if __name__ == "__main__":
    app = wx.App(False)
    frame = MyForm()
    frame.Show()
    app.MainLoop()
Reply


Messages In This Thread
Adding a Window to a Button wxPython - by ShashankDS - Apr-23-2019, 05:38 AM
RE: Adding a Window to a Button wxPython - by Yoriz - Apr-23-2019, 06:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 490 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  Centering and adding a push button to a grid window, TKinter Edward_ 15 4,729 May-25-2023, 07:37 PM
Last Post: deanhystad
  [Tkinter] Clicking on the button crashes the TK window ODOshmockenberg 1 2,240 Mar-10-2022, 05:18 PM
Last Post: deanhystad
  adding button status updates to countdown counter knoxvilles_joker 7 3,387 Apr-18-2021, 01:59 AM
Last Post: knoxvilles_joker
Question closing a "nested" window with a button in PySimpleGUI and repeating this process Robby_PY 9 13,565 Jan-18-2021, 10:21 PM
Last Post: Serafim
  Adding an image to a tkinter window djwilson0495 2 8,077 Aug-23-2020, 11:07 AM
Last Post: ebolisa
  Closing window on button click not working kenwatts275 4 3,755 May-03-2020, 01:59 PM
Last Post: deanhystad
  tkinter window and turtle window error 1885 3 6,717 Nov-02-2019, 12:18 PM
Last Post: 1885
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 5,009 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  [Tkinter] Tkinter window pop up again when i click button Orimura_Sandy 1 3,327 May-12-2019, 08:17 PM
Last Post: joe_momma

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020