This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients louielu, terry.reedy
Date 2017-07-10.01:53:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
We already know that setting StringVar font_name triggers a change to changes.  We also know that manually clicking or Up or Down triggers <<ListBoxSelect>>, which sets font_name and redraws the box.  The challenge is to do something that will trigger the virtual event.  Then we can write a test methods something like

    def test_sample(self):
        fontlist = configure.fontlist
        if fontlist.size():
            name0 = fontlist.get(0).lower()
            # fontlist.selection_set(0)  # or something
            print('\n', changes)  # temp to testing that changes changes
            self.assertEqual(changes['main']['EditorWindow']['font'], name0)
But selection_set does not trigger the event.  After fiddling around with various bindings event_generate()s and update()s and update_idletasks(), I concluded, again, that either event_generate or its documentation is badly broken.  The only thing I got to work in hours of experiments is this:

import tkinter as tk
root = tk.Tk()
seq = '<ButtonRelease-1>'
root.bind(seq, lambda event: print('generated', event))
root.update_idletasks()  # or update()
# update here fails

Adding a widget and binding to the widget always failed.

Here is my attempt using Serhiy's simulate_mouse_click.  (This goes in test_configdialog.FontTabTest.

    def test_sample(self):
        fontlist = configure.fontlist
        if fontlist.size():
            name0 = fontlist.get(0).lower()
            x, y, dx, dy = fontlist.bbox(0)
            fontlist.bind('<ButtonRelease-1>', lambda event: print(event))
            mouse_click(fontlist, x + dx//2, y + dy//2)
            print('\n', changes)  # temporary, see if changes has anything
            self.assertEqual(changes['main']['EditorWindow']['font'], name0)

Serhiy, do you have any idea why I cannot get event_generate to work for a listbox, even with your function? I have tried somewhere close to 20 variations.
Date User Action Args
2017-07-10 01:53:56terry.reedysetrecipients: + terry.reedy, louielu
2017-07-10 01:53:56terry.reedysetmessageid: <>
2017-07-10 01:53:56terry.reedylinkissue30870 messages
2017-07-10 01:53:55terry.reedycreate