问题
I am using IDLE to learn Python 2.7 on Windows 7.
The Vertical scroll bar works fine but I cannot find
a way to activate the Horizontal scroll bar.
Is there a horizontal scroll bar in Python's IDLE?
Thanks
回答1:
Horizontal Scroll Bars for IDLE
from http://code.activestate.com/lists/python-list/26878/ (not my code, found it on this site) It is dated Wed, 08 Mar 2000
Works for Python 2.6 but I can't get to work in 2.7. I get an error saying that the file is open some where. For me, the file he is talking about is located in:C:\Python27\ArcGIS10.1\Lib\idlelib It will be different if you do not have the ArcMap program which comes with python and installs it for you.
I finally got around to adding horizontal scroll bars to the IDLE editor window to help when you get those LONG lines of code. They changes are rather mionor (4 new lines of code) and were made in the EditorWindow.py module. To make the changes in IDLE, open EditorWindow.py and perform a search for 'vbar' which is in the EditorWindow class,
__init__
method. Add those lines that have###
appended to them and VOILA you have it. Unfortunately, the scrollbar appears BELOW the row and column information in IDLE 0.5 (sigh).self.vbar = vbar = Scrollbar(top, name='vbar') self.hbar = hbar = Scrollbar(top, orient=HORIZONTAL, name='hbar') ### ... vbar['command'] = text.yview vbar.pack(side=RIGHT, fill=Y) hbar['command'] = text.xview ### hbar.pack(side=BOTTOM, fill=X) ### text['yscrollcommand'] = vbar.set text['xscrollcommand'] = hbar.set ###
Hope this is helpful.
Jonathan Polley
jwpolley at collins.rockwell.com
回答2:
No. IDLE does not have horizontal scrollbars for two reasons:
- Its text editor has few features.
- You shouldn't be writing long lines of code. See the Maximum Line Length section of the PEP 8 Style Guide for Python Code
回答3:
I'm using IDLE 2.7.3, Windows 7, and I can scroll horizontally by holding down the center mouse button/scroll wheel, and "dragging" around the cursor like that.
回答4:
I may not be a Python expert/guru yet but this question is a user-experience / usability question more than anything. Some might say "Yeah, PEP 8 style guide... blah blah blah" but if I have the IDLE window a certain size (let's say small width), there's no reason I as a user shouldn't be able to scroll. It's simply poor user-experience as a result of poor design.
回答5:
No, the text scrolls horizontally based on where the insertion point or selection is.
回答6:
See http://bugs.python.org/issue1207613
The IdleX project provides an extension for displaying a horizontal scroll bar in IDLE.
回答7:
No, because Python PEPs emphasize, that line length should be 79 symbols at most. Most of the people violates this of course.
回答8:
Horizontal Scroll Bars for IDLE, for Python 3.6.
Thanks to Amber and his/her answer, I've found the way to make it work for Python 3.6.
You have to make some changes in the same class EditorWindow
, but now it's located in a different module: "editor.py" at %python%\Lib\idlelib\ (win).
First you have to make a change in the same method __init__
. And then create a new method handle_xview
for the same class.
Here is the code, you have to add the lines that end with ###
:
self.vbar = vbar = Scrollbar(text_frame, name='vbar')
self.hbar = hbar = Scrollbar(text_frame, orient=HORIZONTAL, name='hbar') ###
...
vbar['command'] = self.handle_yview
vbar.pack(side=RIGHT, fill=Y)
text['yscrollcommand'] = vbar.set
hbar['command'] = self.handle_xview ###
hbar.pack(side=BOTTOM, fill=X) ###
text['xscrollcommand'] = hbar.set ###
And the method:
...
def handle_yview(self, event, *args):
...
...
def handle_xview(self, event, *args): ###
"Handle Horizontal scrollbar." ###
self.text.xview(event, *args) ###
return 'break' ###
...
来源:https://stackoverflow.com/questions/10301071/is-there-a-horizontal-scroll-bar-in-pythons-idle