第一次发布海报,发现该网站在注册之前非常有用。 我在Python 2.7(Windows7)上使用Tkinter时遇到问题: 代码(我已将其截断,因为整个事情是巨大的)看起来像这样:
-------------------------------------------------------
CODE:
#set up stuff, importing variables, etc, then we have:
class App:
global RXSerial
RXSerial=''
#The following lines define the topFrame, lays out the widgets.
def __init__(self, master):
topFrame = Frame(master)
topFrame.pack()
middleFrame = Frame(master)
middleFrame.pack()
#--------------defining state variables------------
self.inputConsole = Text(middleFrame)
self.inputConsole.insert(INSERT,"Data recieved from Serial:")
self.inputConsole.config(width=100,height=20)
self.inputConsole.pack(side=LEFT,padx=20,pady=20)
#blah blah blah, insert a bunch of stuff (buttons etc.) here:
#The following lines define the functions to be called when the buttons are pressed.
def engineFire(self,engineUse,pwm):
RXSerial='this should pop up in the text called inputConsole'
print RXSerial
self.inputConsole.insert(INSERT, RXSerial)
---------------------------------------------------
所以是的,基本上RXSerial是一个字符串(我检查过它正在工作,当按钮调用时,打印RXSerial行成功打印。问题是self.inputConsole.insert(INSERT,RXSerial)行不是任何人都可以帮忙吗?我已经尝试了很多东西的组合,但似乎无法让它工作。谢谢。
答案 0 :(得分:0)
如果您尝试从其他线程插入文本,则可能无法正常工作。此外,如果在某些时候您将文本窗口小部件配置为处于禁用状态,则插入将失败。如果是这种情况(窗口小部件被禁用),暂时将状态设置为“正常”将解决问题。
没有更多信息,我们无法肯定地说出来。