문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top