Click here to Skip to main content
15,878,959 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi,

I'm trying to write a very simple script. The script creats a GUI window in which there is a button. When the user writes something to the console window, the color of the font of the button is changed. I don't understand why it doesn't work.

This is the code:

Python
from Tkinter import *

master = Tk()
button=Button(master,text="hello", fg="blue")
button.pack()
master.mainloop()

raw_input()
button.config(fg="red")
button.pack()
Posted

1 solution

The UI code blocked the main process.
Here is my modification:
from Tkinter import *
import threading

class UIChanger(threading.Thread):

    def run(self):
        config = raw_input()
        while config != 'over':
            button.config(fg=config)
            button.pack()
            config = raw_input()
        print "Quit console input"

ui_changer = UIChanger()
ui_changer.start()
master = Tk()
button=Button(master,text="hello", fg="blue")
button.pack()
master.mainloop()

print "Game Over"


See the screenshot[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900