1

First time poster, found the site very helpful before registering though. I am having issues using Tkinter on Python 2.7 (Windows7): The code (I have truncated it because the whole thing is massive) looks something like this:

-------------------------------------------------------
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)
---------------------------------------------------

so yeah, basically RXSerial is a string (that I have checked that is working, the print RXSerial line successfully prints when called by a button. The problem is that the self.inputConsole.insert(INSERT,RXSerial) line is not working. Can anybody please help? I have tried a bunch of combinations of stuff but cant seem to get it working. Thank you.

1
  • 1
    How do you call engineFire? Not from another thread, perchance? Tkinter, like most GUI frameworks, has thread affinity. Look here: effbot.org/zone/tkinter-threads.htm Commented Sep 5, 2012 at 6:41

1 Answer 1

3

If you're trying to insert the text from another thread it may fail to work. Also, if at some point you configured the text widget to be in the disabled state then inserting will fail. If that's the case (widget is disabled), setting the state to "normal" temporarily will solve the problem.

Without more information it's impossible to say for sure.

Sign up to request clarification or add additional context in comments.

2 Comments

hey, thats the weird thing. im not currently using thread or threading (they are not even imported), and if i try to print a test string (eg. self.inputConsole.insert(INSERT,"blahblahblah") it will print fine. printing (to IDLE window) the variable also works fine, its just when you try to put them together.
@LHC: have you verified that the widget is not disabled?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.