Tkinter - changing existing Dialog?

  • Thread starter Michael Yanowitz
  • Start date
M

Michael Yanowitz

Hello:


I have a Tkinter GUI Dialog with many buttons and labels and text
widgets.
What I would like to do is, can I:

1) Disable/deactivate/hide a button, text widget that is already drawn (and
of course the opposite enable/activate/show it)?

2) Change the text of a label or button that is already drawn?

based on actions taken by the user. Can it be done without destroying
the present dialog or the objects in it and creating a new one?

Sorry for what probably is such a trivial and basic question. I just can't
find the answer or know what the technical term for what I want to do is to
search for it myself.

Thanks in advance:
Michael Yanowitz
 
C

Cameron Laird

Hello:


I have a Tkinter GUI Dialog with many buttons and labels and text
widgets.
What I would like to do is, can I:

1) Disable/deactivate/hide a button, text widget that is already drawn (and
of course the opposite enable/activate/show it)?
.
.
.
import Tkinter

root = Tkinter.Tk()

def actions():
print "Someone pushed the button."
b.configure(state = Tkinter.DISABLED)

b = Tkinter.Button(root, text = "Push me", command = actions)
b.pack()
root.mainloop()
 
C

Cameron Laird

.
.
.
2) Change the text of a label or button that is already drawn?

based on actions taken by the user. Can it be done without destroying
the present dialog or the objects in it and creating a new one?
.
.
.
import Tkinter

root = Tkinter.Tk()

counter = 0

# This is one of several ways one can access the Button's label.
def set_text():
b.configure(text = "The button has been pushed %d time(s)." % counter)

def actions():
global counter
counter += 1
set_text()

b = Tkinter.Button(root, command = actions)
set_text()
b.pack()
root.mainloop()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,297
Messages
2,571,536
Members
48,283
Latest member
SherriP988

Latest Threads

Top