473,387 Members | 1,517 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,387 software developers and data experts.

Changing button preferences after beeing pressed

Hello

I'm using wxPython to consruct a GUI and want to change a button label
and event handler to change after the button have been pressed. The
only thing I can think of is a global variable that contrls the state
of the program and constructs the button in accordance to the defined
state. Is there a better solution to this problem?

/Thomas

Aug 16 '07 #1
2 1329
th***************@gmail.com wrote:
I'm using wxPython to consruct a GUI and want to change a button
label
=wx.Button.SetLabel (also have a look at the button examples)
and event handler to change after the button have been
pressed.
I'm not sure if those bindings can easily be changed at runtime.
Another solution is creating two buttons and only show one at a
time.
The only thing I can think of is a global variable that
contrls the state of the program and constructs the button in
accordance to the defined state.
Better keep the state as frame attribute and use a frame method to
change it.

Regards,
Björn

--
BOFH excuse #61:

not approved by the FCC

Aug 16 '07 #2
th***************@gmail.com wrote:
Hello

I'm using wxPython to consruct a GUI and want to change a button label
and event handler to change after the button have been pressed. The
only thing I can think of is a global variable that contrls the state
of the program and constructs the button in accordance to the defined
state. Is there a better solution to this problem?
It would be difficult to think of a worse one! ;-)

Since the button is probably in some sort of window, you should at least
be saving the state as an instance variable of the window. The event
handler should start with an "if" statement that calls one or other of
the routines you have in mind depending on state. Here's a button
event-handlerI use in a time recording program:

def OnPauseRestart(self, event):
"""Stops/restarts the clock: allows for non-recordable
activities."""
if self.Running:
self.stopTimer()
else:
self.startTimer()

def startTimer(self):
"""Starts the timer and returns the time to black."""
if not self.currentTask:
msg("Please select a task before starting the timer",
caption="No current task")
return
self.timer.Start(1000)
self.Time().SetForegroundColour(wx.BLACK)
self.Time().Refresh()
self.Pause().SetLabel("&Pause")
self.Running = 1

def stopTimer(self):
"""Stops the timer and sets the time red - you are not
chargeable!"""
self.timer.Stop()
self.Time().SetForegroundColour(wx.RED)
self.Time().Refresh()
self.Pause().SetLabel("&Resume")
self.Running = 0

Hope this helps.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

Aug 16 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: robert | last post by:
hi! I want to have a custom button change appearance when pressed and then call a function and change back to its original appearance when released. here's what i have now, which works mostly....
3
by: James McGivney | last post by:
I have a project in VS.NET using C# I have a series of buttons on an aspx page. When one of the buttons is pressed, a panel becomes visible and allows the user to enter and edit data. I want to...
3
by: James McGivney | last post by:
I have a project in VS.NET using C# I have a series of buttons on an aspx page. When one of the buttons is pressed, a panel becomes visible and allows the user to enter and edit data. I want to...
19
by: darrel | last post by:
On my vb.net page, I have 4 sets of inputs + form buttons. example: Search: (GO) Zip: (GO) County: (GO) County: (GO) The problem is if I go to the page, type in a zip code, and hit...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.