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 8387441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:12:42+00:00 2026-06-09T18:12:42+00:00

I’ve created a wxframe with a button which when clicked brings up a child

  • 0

I’ve created a wxframe with a button which when clicked brings up a child frame that generates text controls with data stored from a dictionary named “samples” as shown below. The idea of the child frame is that it is an edit window for editing the data.

My problem is I don’t know how to retrieve data from the generated text controls. I can only get data from the last generated text control.

Here is a simplified version of the code I created:

import wx

class MyFrame1(wx.Frame):


    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame1.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        self.frame=wx.Frame.__init__(self, *args, **kwds)
        self.panel_1 = wx.Panel(self, -1)
        self.f3 = wx.Frame(None,-1,'Edit Tags')

        self.editTag = wx.Button(self.panel_1, -1, "Edit Tags", size=(100, 50))
        self.editTag.Bind(wx.EVT_BUTTON, self.editTags)

        self.Bind( wx.EVT_CLOSE, self.CloseAll)



        # end wxGlade

#-------------------------------------------------------------------------------
    def editTags(self, event):  # wxGlade: MyFrame.<event_handler>
        samples={
              "Face1":"(100,100)", \
              "Face2":"(50,40)", \
              "Car":"(500,230)", \
              "Wallclock":"(120,230)"

            }

        self.f3.okButton = wx.Button(self.f3, label="OK")
        self.f3.okButton.Bind(wx.EVT_BUTTON, self.onOK)
        self.f3.okButton.SetPosition((40,200))

        spacer=0

        for k, v in sorted(samples.iteritems()):
            print "K: ", k

            spacer=spacer+40
            print "V: ", v
            print

        self.f3.new_TextControl = wx.TextCtrl(self.f3, -1, value=k)
        self.f3.new_TextControl.SetPosition((40,spacer))

        print

        self.f3.Show()

   #-------------------------------------------------------------------------------
    def onOK(self, event):  # wxGlade: MyFrame.<event_handler>
        print self.f3.new_TextControl.GetValue()
        print self.f3.new_TextControl.GetValue()
        print "OK clicked"
        self.f3.Hide()
   #-------------------------------------------------------------------------------

    def CloseAll(self, event):
        self.DestroyChildren()  # First destroy child frames
        self.Destroy()          # Then destroy the parent frame
        self.f3.Close()
        self.Close()
   #-------------------------------------------------------------------------------

    # end of class MyFrame1
    if __name__ == "__main__":
        app = wx.PySimpleApp(0)
        frame_1 = MyFrame1(None, -1, "")
        app.SetTopWindow(frame_1)
        frame_1.Show()
        app.MainLoop()

Any alternative solutions are welcome as well

I’m using python 2.7.2. and wxpython

  • 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-09T18:12:44+00:00Added an answer on June 9, 2026 at 6:12 pm

    Let’s look through your code:

    def editTags(self, event):  # wxGlade: MyFrame.<event_handler>
        samples={
              "Face1":"(100,100)", \
              "Face2":"(50,40)", \
              "Car":"(500,230)", \
              "Wallclock":"(120,230)"
    
            }
    
        self.f3.okButton = wx.Button(self.f3, label="OK")
        self.f3.okButton.Bind(wx.EVT_BUTTON, self.onOK)
        self.f3.okButton.SetPosition((40,200))
    

    Let’s make a storage for your new controls (will discuss it below):

        self.f3.new_controls = {}
    
        spacer=0
    

    Here you iterate over your future fields and here’s a problem:

        for k, v in sorted(samples.iteritems()):
            print "K: ", k
    
            spacer=spacer+40
            print "V: ", v
            print
    

    The next step: you actually create your controls. Here is where some issues hide:

    1. You create it out of your cycle, you must put them inside for-loop block (in your variant only one text control (stored in new_TextControl field is created)), and it will be a field for the last iterated v value (that’s how for works).
    2. You need to create some container (remember self.f3.new_controls we created above?) to hold your controls (e.g. a dict).

    So let’s make some further changes to your code:

            # Dict will hold {'Car': wx.TextCtrl(...), 'Wallclock': ...}
            self.f3.new_controls[k] = wx.TextCtrl(self.f3, -1, value=k)
            self.f3.new_controls[k].SetPosition((40,spacer))
    

    And you show your frame, that’s ok:

        self.f3.Show()
    

    You can access values of newly created fields from new_controls dict:

    self.f3.new_controls['Car'].GetValue()  # Receive input from 'Car' text control.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to select an H1 element which is the second-child in its group
I want to construct a data frame in an Rcpp function, but when I
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text

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.