python - Causing a Tkinter widget to change based on input from another widget -
i have created simple command-line game , considering porting gui. way able give player option make choices through clicking buttons, instead of being forced type in text.
my problem tricky without ability change text on label , button widgets, how might 1 go doing this?
here have far (after laurencevs's answer):
def goaway(event): label02.configure(text = " ") label01.configure(text = "go away") time.sleep(1) label01.configure(text = "go away.") time.sleep(1) label01.configure(text = "seriously, go away!") time.sleep(1) label01.configure(text = "that's it.") time.sleep(0.5) quit("goodbye.") button01 = button(root, text="click me, see happens.") button01.grid(row=1001, column=1001) button01.bind("<button-1>", goaway)
but wait 3 seconds , close program. how can fix this
the idea when clicked button change text in label label01
"go away", wait 1 second, change text "go away.", etc. , quit, printing "goodbye" users running in terminal.
you absolutely can change text on label or button.
all have use label.configure()
method. want change text in label1
"don't panic", this:
label1.configure(text = "don't panic")
the same goes buttons , other widgets.
if want create button when clicked, must define function changes label's text, , use function's name (for example foo
) when creating button this:
button = button(window, text = "i button", command = foo)
the full code this:
from tkinter import * # tkinter in python 2 def foo(): label1.configure(text = "don't panic") window = tk() # other (optional) window setup here label1 = label(window, text = "") button = button(window, text = "i button", command = foo) # pack label , button , initiate window's mainloop here
Comments
Post a Comment