473,388 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

How to access a global object in another function?

i have two buttons, which are disabled on page load,
when i select one radio button i have to make that button enable.
But when i write button1.Enable() in the radibutton click event, its showing an error "global object 'button1' not defined.

How can i tackle this problem.

How can i access a global variable in another function?
Feb 7 '11 #1

✓ answered by bvdet

Make your button available to other methods in your application by defining it like this:
Expand|Select|Wrap|Line Numbers
  1. self.button1 = wx.Button(panel,label="Export",pos=(75,120),size=(50,30))
The button and its methods will be available in other methods if accessed using self.button1

3 1966
bvdet
2,851 Expert Mod 2GB
To make a variable available to the global scope, declare the variables with the global statement before the variables are used in a given block of code.

For example:
Expand|Select|Wrap|Line Numbers
  1. def foo():
  2.     global foobar
  3.     foobar = "This variable will be available in the global scope"
This is not good programming style however. Most GIU applications are encapsulated in class objects where an instance of the class has a namespace implemented as a dictionary, containing the attributes defined.
Feb 7 '11 #2
Actually I need to create a button
Expand|Select|Wrap|Line Numbers
  1. class myApp(wx.Frame):
  2. def __init__(self,parent,id):
  3.         wx.Frame.__init__(self,parent,id,'Export Form', size=(500,500))
  4.         panel =wx.Panel(self)
  5. #Creating Buttons
  6.         global button1 = wx.Button(panel,label="Export",pos=(75,120),size=(50,30))
in another click event i wnt to make this button disable, i tried with your sujjestion, it didnt worked. is there any other way
Expand|Select|Wrap|Line Numbers
  1.  def chain(self,event):
  2.         global button1.Disable()
is this possible
Feb 7 '11 #3
bvdet
2,851 Expert Mod 2GB
Make your button available to other methods in your application by defining it like this:
Expand|Select|Wrap|Line Numbers
  1. self.button1 = wx.Button(panel,label="Export",pos=(75,120),size=(50,30))
The button and its methods will be available in other methods if accessed using self.button1
Feb 7 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jimmy Jim | last post by:
Hey all, quick question to see if anyone has any ideas. I have an object: $special = new special; Let's say I have a function: class special { function outputtext() { return "test";
4
by: Andrew V. Romero | last post by:
I have been working on a function which makes it easier for me to pull variables from the URL. So far I have: <script language="JavaScript"> var variablesInUrl; var vArray = new Array(); ...
7
by: Joakim Braun | last post by:
Why doesn't the below code work? I'm trying to create a global object and set an event handler to one of its methods. The function is called, but the object's mTest property is undefined. ...
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
4
by: wh | last post by:
I really just need some reassurance that I'm doing the right thing really. Here goes... I have an object which needs to be available to all sessions. This is being created in the...
0
by: Fabian | last post by:
Hi, I work in asp.net 2.0 create an object in my global.asax file with this code <object Class="myApp.Class" Id="myClass" RunAt="server" Scope="application" /> <script Language="C#"...
16
by: Roman Ziak | last post by:
Hello, there were times when I used to be looking for a way to access JavaScript Global object similar to those found in VBScript or PHP ($GLOBALS). At present this has only academic value for...
3
by: User1014 | last post by:
A global variable is really just a property of the "Global Object", so what does that make a function defined in the global context? A method of the Global Object? ...
5
by: Sam.Gundry | last post by:
Hi, I wish to share an object through a bunch of functions without declaring it globally. I have achieved this through the following function: VideoReceiver* getReceiver() { static...
15
by: Bob | last post by:
Is there anyway to access the global object from inside a function other than doing a "var _global = this;" before declaring the function? Thanks
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.