Domanda

I have made a programm with some simple Tkinter windows, for example a 'Hello' label. Is it possible to type and give commands in Python Shell simultaneously? I tried but Python Shell doesn't appear '>>>' to give commands,so when i type and press Enter , the cursor goes to the next line,instead of running the string. I hope you get my point

È stato utile?

Soluzione

You want to see the open window and simultaniously execute commands behind >>>.

Two solutions I see:

  1. remove xxx.mainloop() when you execute it with the Python Shell. I did it like this conditionally.

    import sys
    if 'idlelib' not in sys.modules:
         xxx.mainloop()
    
  2. start the mainloop in another thread. You should not do this in production code because Tkinter is not threadsafe.

     import threading
     t = threading.Thread(target = xxx.mainloop)
     t.start()
    

These are two solution I could think of because 1. may not always work.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top