How to bind events to Canvas items?

To interact with objects contained in a Canvas object you need to use tag_bind() which has this format: tag_bind(item, event=None, callback=None, add=None) The item parameter can be either a tag or an id. Here is an example to illustrate the concept: from tkinter import * def onObjectClick(event): print(‘Got object click’, event.x, event.y) print(event.widget.find_closest(event.x, event.y)) root … Read more

What is the difference between the Control.Enter and Control.GotFocus events?

The GotFocus/LostFocus events are generated by Windows messages, WM_SETFOCUS and WM_KILLFOCUS respectively. They are a bit troublesome, especially WM_KILLFOCUS which is prone to deadlock. The logic inside Windows Forms that handles the validation logic (Validating event for example) can override focus changes. In other words, the focus actually changed but then the validation code moved … Read more

Cross-thread operation not valid [duplicate]

You can’t. UI operations must be performed on the owning thread. Period. What you could do, is create all those items on a child thread, then call Control.Invoke and do your databinding there. Or use a BackgroundWorker BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += (s, e) => { /* create items */ }; bw.RunWorkerCompleted += … Read more

Ideal size for .ico

Short answer: 16 x 16 pixels. Long answer: .ico files can actually contain multiple images, at multiple colour depths – you can provide 16×16, 32×32, 48×48 and 64×64 in a single file and the OS will pick the best one to show. Of course to keep the file size low you don’t want to put … Read more

JavaFX FileChooser: how to set file filters?

You could do: FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter(“TXT files (*.txt)”, “*.txt”); chooser.getExtensionFilters().add(extFilter); Here is a simple example: public class ExtensionFilterExample extends Application { public static void main(String[] args) { launch(args); } @Override public void start(final Stage primaryStage) { primaryStage.setTitle(“Extension Filter Example”); final Label fileLabel = new Label(); Button btn = new Button(“Open FileChooser”); btn.setOnAction(new EventHandler<ActionEvent>() … Read more