Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Terry Reedy Newsgroups: comp.lang.python Subject: Re: Resources/pointers for writing maintable, testable Python Date: Thu, 19 May 2016 18:45:30 -0400 Lines: 67 Message-ID: References: <909ee5e9-ae16-4ebe-a6c1-c838ff3bb8fd@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de hxGnG3fsD2XXYLe2mde2jAqdjFFQoUm5iASkYjCEboUA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'handler': 0.04; 'root': 0.04; 'subject:Python': 0.05; "'a'": 0.07; 'apps,': 0.07; 'keys,': 0.07; 'mouse': 0.07; 'works.': 0.07; "'''": 0.09; 'events.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'reference)': 0.09; 'jan': 0.11; 'thursday,': 0.13; 'def': 0.13; 'argument': 0.15; '*before*': 0.16; '2016': 0.16; '54,': 0.16; 'buttons,': 0.16; 'called,': 0.16; 'curious.': 0.16; 'driscoll': 0.16; 'entry.': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'reminding': 0.16; 'selenium': 0.16; 'simulate': 0.16; 'simulated': 0.16; 'subject:writing': 0.16; 'wrote:': 0.16; 'specifies': 0.18; 'widget': 0.18; 'commands,': 0.22; 'object.': 0.22; 'referring': 0.22; 'tkinter': 0.22; 'needed.': 0.23; 'import': 0.24; 'url:edu': 0.24; 'header:In-Reply-To:1': 0.24; 'discussion': 0.24; 'header:User-Agent:1': 0.26; 'header:X -Complaints-To:1': 0.26; 'external': 0.27; 'handling': 0.27; 'sequence': 0.27; 'values': 0.28; 'arguments,': 0.29; 'screen.': 0.29; 'mike': 0.29; 'subject:/': 0.30; 'skip:. 10': 0.32; 'idle': 0.33; 'case,': 0.34; 'could': 0.35; 'text': 0.35; 'done': 0.35; 'but': 0.36; 'needed': 0.36; '(and': 0.36; 'keyword': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'thanks': 0.37; 'received:org': 0.37; 'button': 0.38; 'test': 0.39; 'skip:e 20': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'some': 0.40; 'field': 0.60; 'providing': 0.62; 'received:96': 0.63; 'more': 0.63; 'url:help': 0.73; 'clicking': 0.75; '**kw)': 0.84; 'events:': 0.84; 'perspective.': 0.84; 'url:tkinter': 0.84; 'received:fios.verizon.net': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: pool-96-227-207-81.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 In-Reply-To: <909ee5e9-ae16-4ebe-a6c1-c838ff3bb8fd@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <909ee5e9-ae16-4ebe-a6c1-c838ff3bb8fd@googlegroups.com> Xref: csiph.com comp.lang.python:108847 On 5/19/2016 4:10 PM, Mike Driscoll wrote: > On Thursday, May 19, 2016 at 11:23:53 AM UTC-5, Terry Reedy wrote: >> In my case, I learned better how to test IDLE from a user perspective.= >> For tkinter apps, an external program such as Selenium is not needed. >> Tk/tkinter have the simulated event generation and introspection neede= d >> to simulate a user hitting keys, clicking mouse buttons, and reading t= he >> screen. > I am curious. Where is this documented? Are you referring to calling > the invoke() method on each widget? For widget commands, yes. (And thanks for reminding of the method.) For events: http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/universal.html (An indispensible tkinter reference) says: ''' w.event_generate(sequence, **kw) This method causes an event to trigger without any external=20 stimulus. The handling of the event is the same as if it had been=20 triggered by an external stimulus. The sequence argument describes the=20 event to be triggered. You can set values for selected fields in the=20 Event object by providing keyword=3Dvalue arguments, where the keyword=20 specifies the name of a field in the Event object. See Section 54, =E2=80=9CEvents=E2=80=9D for a full discussion of ev= ents. ''' This omits some essentials. tcl.tk/man/tcl8.6/TkCmd/event.htm has much more, including the need to put focus on Text and Entry. From Stackoverflow, I learned that .update() is needed *before*=20 =2Eevent_generate. The following works. import tkinter as tk root =3D tk.Tk() def prt(): print('Handler called') button =3D tk.Button(root, text=3D'Click', command=3Dprt) button.place(x=3D20, y=3D20) def ev(e): print(e.x, e.y) button.bind('', ev) button.update() button.event_generate('', x=3D0, y=3D0) button.event_generate('') button.invoke() entry=3Dtk.Entry(root) entry.place(x=3D20, y=3D50) entry.focus_force() entry.update() entry.event_generate('') The event is reported, the handler is called, and 'a' is inserted.=20 (Inserting text could be done more easily, but some key events such as=20 do have text equivalents.) --=20 Terry Jan Reedy