第一次发帖,虽然在注册之前发现该网站非常有用。我在 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) 行不工作。可以有人请帮忙吗?我尝试了一堆东西的组合,但似乎无法让它工作。谢谢。