You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<h3>25.5.3.3. IDLE-console differences<aclass="headerlink" href="#idle-console-differences" title="Permalink to this headline">¶</a></h3>
576
-
<p>As much as possible, the result of executing Python code with IDLE is the
577
-
same as executing the same code in a console window. However, the different
578
-
interface and operation occasionally affect visible results. For instance,
579
-
<codeclass="docutils literal"><spanclass="pre">sys.modules</span></code> starts with more entries.</p>
576
+
<p>With rare exceptions, the result of executing Python code with IDLE is
577
+
intended to be the same as executing the same code in a console window.
578
+
However, the different interface and operation occasionally affect
579
+
visible results. For instance, <codeclass="docutils literal"><spanclass="pre">sys.modules</span></code> starts with more entries.</p>
580
580
<p>IDLE also replaces <codeclass="docutils literal"><spanclass="pre">sys.stdin</span></code>, <codeclass="docutils literal"><spanclass="pre">sys.stdout</span></code>, and <codeclass="docutils literal"><spanclass="pre">sys.stderr</span></code> with
581
581
objects that get input from and send output to the Shell window.
582
-
When this window has the focus, it controls the keyboard and screen.
583
-
This is normally transparent, but functions that directly access the keyboard
582
+
When Shell has the focus, it controls the keyboard and screen. This is
583
+
normally transparent, but functions that directly access the keyboard
584
584
and screen will not work. If <codeclass="docutils literal"><spanclass="pre">sys</span></code> is reset with <codeclass="docutils literal"><spanclass="pre">importlib.reload(sys)</span></code>,
585
585
IDLE’s changes are lost and things like <codeclass="docutils literal"><spanclass="pre">input</span></code>, <codeclass="docutils literal"><spanclass="pre">raw_input</span></code>, and
586
586
<codeclass="docutils literal"><spanclass="pre">print</span></code> will not work correctly.</p>
<codeclass="docutils literal"><spanclass="pre">exec</span></code> to run each statement. As a result, <codeclass="docutils literal"><spanclass="pre">'__builtins__'</span></code> is always
<h3>25.5.3.4. Developing tkinter applications<aclass="headerlink" href="#developing-tkinter-applications" title="Permalink to this headline">¶</a></h3>
594
+
<p>IDLE is intentionally different from standard Python in order to
595
+
facilitate development of tkinter programs. Enter <codeclass="docutils literal"><spanclass="pre">import</span><spanclass="pre">tkinter</span><spanclass="pre">as</span><spanclass="pre">tk;</span>
596
+
<spanclass="pre">root</span><spanclass="pre">=</span><spanclass="pre">tk.Tk()</span></code> in standard Python and nothing appears. Enter the same
597
+
in IDLE and a tk window appears. In standard Python, one must also enter
598
+
<codeclass="docutils literal"><spanclass="pre">root.update()</span></code> to see the window. IDLE does the equivalent in the
599
+
background, about 20 times a second, which is about every 50 milleseconds.
600
+
Next enter <codeclass="docutils literal"><spanclass="pre">b</span><spanclass="pre">=</span><spanclass="pre">tk.Button(root,</span><spanclass="pre">text='button');</span><spanclass="pre">b.pack()</span></code>. Again,
601
+
nothing visibly changes in standard Python until one enters <codeclass="docutils literal"><spanclass="pre">root.update()</span></code>.</p>
602
+
<p>Most tkinter programs run <codeclass="docutils literal"><spanclass="pre">root.mainloop()</span></code>, which usually does not
603
+
return until the tk app is destroyed. If the program is run with
604
+
<codeclass="docutils literal"><spanclass="pre">python</span><spanclass="pre">-i</span></code> or from an IDLE editor, a <codeclass="docutils literal"><spanclass="pre">>>></span></code> shell prompt does not
605
+
appear until <codeclass="docutils literal"><spanclass="pre">mainloop()</span></code> returns, at which time there is nothing left
606
+
to interact with.</p>
607
+
<p>When running a tkinter program from an IDLE editor, one can comment out
608
+
the mainloop call. One then gets a shell prompt immediately and can
609
+
interact with the live application. One just has to remember to
610
+
re-enable the mainloop call when running in standard Python.</p>
0 commit comments