New submission from paolo <paolo.fr...@libero.it>: 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 ---------- components: Tkinter messages: 91547 nosy: paolo severity: normal status: open title: Tkinter: modify xview of entry widget versions: Python 2.5 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue6702> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com