classification
Title: Tkinter: modify xview of entry widget
Type: Stage:
Components: Tkinter Versions: Python 2.5
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: gpolo, paolo
Priority: normal Keywords:

Created on 2009-08-14 12:28 by paolo, last changed 2009-08-14 12:42 by gpolo. This issue is now closed.

Messages (2)
msg91547 - (view) Author: (paolo) Date: 2009-08-14 12:28
I wish to propose a useful and smart method modify in Tkinter Library:

Previously to scroll this widget we had to write an external function
(recalling xview_moveto and xview_scroll).

With my method this operation is cleared and the same as all other
widgets (just have to call xview).

----------------------------------------------------------
Modify Proposal:
----------------------------------------------------------
Change the method xview of entry so it works as all widget scrollable,
and it's compatible with 'old' xview.

So to scroll entry widget:

entry_widget['xscrollcommand']=scroll_widget.set
scroll_widget['command']=entry_widget.xview

The change in module Tkinter is:

def xview(self,*args):
    """Query and change horizontal position of the view."""
    #modify
    if not args:
        return self._getdoubles(self.tk.call(self._w, 'xview'))
    #old code
    index=args[0]
    self.tk.call(self._w, 'xview', index)
----------------------------------------------------------
+
It's call the tk interpreter passing entry and xview without arguments;
returns a list containing two elements to pass to scrollbars via the
xscrollcommand option

If an argument (index) is passing, then display the character given by
index at the left edge of the window; it work as the original xview

With 'old' methon is impossible call xview without arguments, the change
has made possible this.

-----------------------------------------------------------------
To scroll entry without modify:
-------------------------------
import Tkinter as tk
root=tk.Tk()

def scollEntry(*args):
   if args[0]=='scroll':
        e.xview_scroll(args[1],args[2])
   if args[0]=='moveto':
        e.xview_moveto(args[1])

e=tk.Entry(width=10)
e.grid(row=0, sticky='e'+'w')

s=tk.Scrollbar(orient='horizontal')
s.grid(row=1, sticky='e'+'w')

e['xscrollcommand']=s.set
s['command']=scollEntry

root.mainloop()

--------------------------------------------------------------------
With modify:
------------
import Tkinter as tk
root=tk.Tk()

e=tk.Entry(width=10)
e.grid(row=0, sticky='e'+'w')

s=tk.Scrollbar(orient='horizontal')
s.grid(row=1, sticky='e'+'w')

e['xscrollcommand']=s.set
s['command']=e.xview

root.mainloop()

-----------------------------------------------------------------
It's work also with tk-8.5 and ttk
----------------------------------
import Tkinter as tk
import ttk
root=tk.Tk()

e=ttk.Entry(width=10)
e.grid(row=0, sticky='e'+'w')

s=ttk.Scrollbar(orient='horizontal')
s.grid(row=1, sticky='e'+'w')

e['xscrollcommand']=s.set
s['command']=e.xview

root.mainloop()
---------------------------------------------------------

I tested with Python 2.5 and tk 8.4 and also tk 8.5 and module ttk
msg91548 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2009-08-14 12:42
Please take a look on issue6180. Closing this as duplicate.

Also consider checking the issue 1135, your comments are welcome on both
issues and may help getting the fix committed.
History
Date User Action Args
2009-08-14 12:42:19gpolosetstatus: open -> closed

nosy: + gpolo
messages: + msg91548

resolution: duplicate
2009-08-14 12:28:15paolocreate