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

Dynamically changing button text in python

Hi all,

I am wondering if i could change a button text dynamically in its
handler.

for example,can we do something like this:

curButton.bind("<Button-1>",self.StopServer)

def StopServer(self,event):
curButton["text"] = "Start Server"

Thanks,
Sundar

Jan 14 '06 #1
5 5220
ma**********@gmail.com writes:
for example,can we do something like this:

curButton.bind("<Button-1>",self.StopServer)

def StopServer(self,event):
curButton["text"] = "Start Server"


Yes.
Jan 14 '06 #2
The problem is once i set the textvariable property of the button,i
cannot change the text.For example,

curButton = Button(root,text="Stop Server",textvariable="this")

curButton.bind("<Button-1>",self.StopServer)

def StopServer(self,event):
curButton["text"] = "Start Server" #this does not work

Jan 15 '06 #3
ma**********@gmail.com writes:
The problem is once i set the textvariable property of the button,i
cannot change the text.For example,

curButton = Button(root,text="Stop Server",textvariable="this")


1. I don't think you can use text and textvariable at the same time.
2. I don't think you're using textvariable the right way.

Try something like:

tv = StringVar()
curButton = Button(root, textvariable=tv)
curButton.bind("<Button-1>",self.StopServer)
def StopServer(self,event):
tv.set("Start Server")

--Paul
Jan 15 '06 #4
ma**********@gmail.com wrote:
The problem is once i set the textvariable property of the button,i
cannot change the text.For example,

curButton = Button(root,text="Stop Server",textvariable="this")


what made you think that setting textvariable to "this" would be a good
idea?

the textvariable option is used to specify a Tkinter variable that's used
to control the button text; e.g.

curVar = Tkinter.StringVar()
curButton = Button(root, textvariable=curVar)

curVar.set("new text")

also see

http://effbot.org/tkinterbook/button.htm
http://effbot.org/tkinterbook/variable.htm

</F>

Jan 15 '06 #5
Thank you very much.I had actually misinterpreted the "textvariable"
property for some kind of "storage for each Button". I am actually
developing an app where multiple buttons have a single event handler.So
i thought the "textvariable" property might be used to store some info
about each of the Button so that the handler can differentiate between
the callers by examining the property.Now i achieved similar
functionality with callbacks because button command handlers dont
receive any additional arguments.

Jan 15 '06 #6

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

Similar topics

10
by: Free-Ed, Ltd. | last post by:
I am going nuts trying to find a paragraph in a book that described how to change the text content (HTML) in a DIV. Actually I have an array of HTML strings that I want to drop into the DIV,...
10
by: Randy Webb | last post by:
This page: http://www.hikksworld.com/loadJSFiles/ Is one where I was testing the ability of browsers that can/can't dynamically load a JS file with one of the three methods: 1)Changing the src...
32
by: Mark Johnson | last post by:
You have an, a, anchor with href link. Can you use a stylesheet to effectively disable the link, so that you can't click on it; that it will appear simply as text?
2
by: RobG | last post by:
I am trying to dynamically add an onclick to an element, however I just can't get the syntax right. consider the following function: function doClick (evt,x) { // do things with evt and x } ...
8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
1
by: Earl Teigrob | last post by:
PROBLEM: When a user control is loaded into a PlaceHolder control more than once, the events do not fire on the first click of a control on the dynamically loaded user control. In other words, the...
3
by: Paulers | last post by:
Hello, I have an arraylist that looks like this: 1,4,6 I have buttons called button1, button4, button6. I would like to change the text on the buttons that corispond to the numbers in the...
4
by: bjjnova | last post by:
I need help dynamically resetting an event handler. I have a form with several buttons. I have intialized the Click event of a particular button thus on the form: _button_3.Click += new...
1
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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.