473,543 Members | 4,429 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1332
th************* **@gmail.com wrote:
I'm using wxPython to consruct a GUI and want to change a button
label
=wx.Button.SetL abel (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.currentTas k:
msg("Please select a task before starting the timer",
caption="No current task")
return
self.timer.Star t(1000)
self.Time().Set ForegroundColou r(wx.BLACK)
self.Time().Ref resh()
self.Pause().Se tLabel("&Pause" )
self.Running = 1

def stopTimer(self) :
"""Stops the timer and sets the time red - you are not
chargeable!"""
self.timer.Stop ()
self.Time().Set ForegroundColou r(wx.RED)
self.Time().Ref resh()
self.Pause().Se tLabel("&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
2825
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. "drop" is my handler for the button, its argument tells me which button was pressed. i have a number of these buttons and they are organized in a...
3
1945
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 use this data to modify the text of the button I am thinking of storing a unique identifier in View State when the button is pressed. After the user...
3
291
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 use this data to modify the text of the button I am thinking of storing a unique identifier in View State when the button is pressed. After the user...
19
2160
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 enter.
0
7402
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7590
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7344
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7684
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5883
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5264
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4890
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3388
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
963
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.