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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:38:15+00:00 2026-06-16T06:38:15+00:00

I can’t change a value from a class. This is my problem : #!/usr/bin/env

  • 0

I can’t change a value from a class.

This is my problem :

#!/usr/bin/env python

import pygtk
pygtk.require20()
import gtk

class MyApp(object):
    def __init__(self):
        self.pencere = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.pencere.connect("delete_event", gtk.main_quit)

        self.b_Up = gtk.Button("UP")
        self.b_Down = gtk.Button("DOWN")
        self.b_Up.connect("pressed", self.ToUp)
        self.b_Down.connect("pressed", self.ToDown)

        self.tablo = gtk.Table(2, 1, False)
        self.tablo.attach(self.b_Up , 0, 1, 0,1)
        self.tablo.attach(self.b_Down, 1, 2, 0, 1 )

        self.pencere.add(self.tablo)

        self.pencere.show_all()
        return

    def ToUp(self, penar  ):
        print "==========ClassUp======= \n" , var_a
        print "@ToUP : " , var_a
        ChangeUp()
        print var_a , "\n=========ClassEndUp========"

    def ToDown(self, penar):
        print "==========ClassDown======= \n", var_a
        print "@ToDown : ", var_a
        ChangeDown()
        print var_a , "\n========ClassEndDown========="

    def main(self):
        gtk.main()

def ChangeUp():
    print "Changing Up : ", var_a
    var_a=["90", "91", "92", "93", "94", "95", "96", "97", "98", "99" ]
    print var_a , "\n================="


def ChangeDown():
    print "Changing Down : " , var_a
    var_a=["0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ]
    print var_a , "\n================="


var_a=["30", "31", "32", "33", "34", "35", "36", "37", "38", "39" ]

app = MyApp()
app.main()

i want to change the var_a list value everywhere
When i click a button ; i am taking an error message :

==========ClassDown======= 
['30', '31', '32', '33', '34', '35', '36', '37', '38', '39']
@ToDown :  ['30', '31', '32', '33', '34', '35', '36', '37', '38', '39']
Changing Down : 
Traceback (most recent call last):
  File "aa.py", line 35, in ToDown
    ChangeDown()
  File "aa.py", line 48, in ChangeDown
    print "Changing Down : " , var_a
UnboundLocalError: local variable 'var_a' referenced before assignment

i want to change var_a list value by clicking . not only in class , everywhere. i tried using “global” but i cant 🙁 (i took an error message).

How can i solve this problem ?

UnboundLocalError: local variable 'var_a' referenced before assignment

i don’t know python well i am beginner. so if u write the code i will be very happy 🙂
thanks a lot !!

  • 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-16T06:38:16+00:00Added an answer on June 16, 2026 at 6:38 am

    Your method defines a new local variable called var_a that hides the global variable with the same name.

    To fix it you can add a global declaration at the beginning of the method:

    def ChangeDown():
        global var_a
        print "Changing Down : " , var_a
        var_a=["0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ]
        print var_a , "\n================="
    

    However I would advise you not to use globals if it is at all possible. Consider using an instance variable instead.

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

Sidebar

Related Questions

Can anyone let me know how can we change the value of kendo combobox
Does anyone know how can I replace this 2 symbol below from the string
Can find why i get this error can someone help? package Android.data; public class
Can I change the field public virtual ClassOne ClassOne { get; set; } to
Can we change the default action of the edit selected row button? Here is
Can I be sure about the order in a Python dictionary? The function op.GetTangent(id)
Can anyone explain to me why this program: for(float i = -1; i <
Can someone please explain to me why the output from the following code is
Can a Check Constraint (or some other technique) be used to prevent a value
Can someone help me understand this question? I may have it on my tomorrow

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.