帮助Python GUI [英] Help with Python GUI
本文介绍了帮助Python GUI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写一个非常简单的脚本。该脚本创建一个GUI窗口,其中有一个按钮。当用户向控制台窗口写入内容时,按钮字体的颜色会发生变化。我不明白为什么它不起作用。
这是代码:
< pre lang =Python> 来自 Tkinter import *
master = Tk ()
button =按钮(master,text = hello,fg = blue)
button.pack()
master.mainloop()
raw_input()
button.config(fg = red )
button.pack()
解决方案
UI代码阻止了主进程。
这是我的修改:
来自Tkinter import *
import threading
class UIChanger(threading。线程):
def run(self):
config = raw_input()
while config!='over':
button.config(fg = config)
button.pack()
config = raw_input()
print退出控制台输入
ui_changer = UIChanger()
ui_changer.start()
master = Tk()
button =按钮(master,text =hello,fg =blue)
button.pack()
master.mainloop()
打印Game Over
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:
from Tkinter import *
master = Tk()
button=Button(master,text="hello", fg="blue")
button.pack()
master.mainloop()
raw_input()
button.config(fg="red")
button.pack()
解决方案
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[^].
这篇关于帮助Python GUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文