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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:39:51+00:00 2026-06-14T11:39:51+00:00

I am writing an application in Python 2.7 using PyGTK 2. Basically I create

  • 0

I am writing an application in Python 2.7 using PyGTK 2. Basically I create TreeView widget, fill it with content and then check if the selection is changed. When it is true I want the selection to be printed in TextView box. My idea is to get selected value, update text and refresh widget. Here is how i get the selected value:

Definition:

class SomeClass:
    def __init__(self):
        ...
        someTextView = build_textview("some text")
        ...
        tree_selection = someTreeView.get_child().get_selection()
        tree_selection.connect("changed", self.selection_changed())
        ...

    # Signal handler: 
    def selection_changed(self, widget, data=None):
        (model, pathlist) = widget.get_selected_rows()
        for path in pathlist :
            tree_iter = model.get_iter(path)
            value = model.get_value(tree_iter,0)
            return value

As you see, selection_changed handler returns value. The question is how can I save that value after handler is called? I know that I can use a global variable or class attribute but it is not an option. I would like the code to look neat. i.e. like that:

tree_selection.connect("changed", value=self.selection_changed())

but of course it doesn’t work.

  • 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-14T11:39:53+00:00Added an answer on June 14, 2026 at 11:39 am

    It doesn’t make sense for a signal handler to return the value, return it where?

    The signal handler should be a method of a class where it makes sense to store the value as an attribute, ie:

    class SomeClass:
        def __init__(self):
            self.value = None
            ...
            someTextView = build_textview("some text")
            ...
            tree_selection = someTreeView.get_child().get_selection()
            tree_selection.connect("changed", self.selection_changed)
            ...
    
        def selection_changed(self, widget, data=None):
            (model, pathlist) = widget.get_selected_rows()
            for path in pathlist :
                tree_iter = model.get_iter(path)
                value = model.get_value(tree_iter,0)
                this.value = value
                return
    

    Notes:

    • __init__ method declares value attribute
    • in connect method change self.selection_changed() for self.selection_changed so you pass the method itself and not the method’s result.
    • selection_changed method stores the value in the attribute and returns nothing.

    Hope it helps.

    Update

    If you still feel your code will look nicer if it explicitly shows where it’s storing the value, you could do something like this:

    def __init__(self):
        self.value = None
        ...
        someTextView = build_textview("some text")
        ...
        def selection_changed_handler(widget, data):
            value = self.selection_changed(widget, data)
    
        tree_selection = someTreeView.get_child().get_selection()
        tree_selection.connect("changed", selection_changed_handler)
        ...
    

    But I think the first one is the standard approach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a multithreaded socket application in Python using the socket module. the
I have problem concerning python packages and testing. I'm writing an application using wx
I am writing multi-threaded python application. The main thread create a Thread pool of
I'm re-writing a legacy Windows application using Python and running on Linux. Initially, the
I'm coding the menu for an application I'm writing in python, using wxPython libraries
I'm writing a web application using python JSON-RPC implementation - http://json-rpc.org/wiki/python-json-rpc on server side
I have started learning Python by writing a small application using Python 3.1 and
I'm writing a python application that has a glade gui. Using subprocess to execute
I'm writing a desktop application in Python using the Qt framework, and it involves
I am writing an application in Qt using python that will process a txt

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.