Re: Generate <Shift-Button> event on a canvas (on Windows)

Liste des GroupesRevenir à cl tcl 
Sujet : Re: Generate <Shift-Button> event on a canvas (on Windows)
De : hgiese (at) *nospam* ratiosoft.com (Helmut Giese)
Groupes : comp.lang.tcl
Date : 06. Aug 2024, 13:10:30
Autres entêtes
Organisation : ratiosoft
Message-ID : <v634bjhn84dkb3easgcapqlpfdi26ujm2e@4ax.com>
References : 1
User-Agent : Forte Free Agent 1.93/32.576 English (American)
To answer my own question: The following script does the trick.
---
package require Tk
foreach ch [winfo children .] {destroy $ch}

set fr [ttk::frame .fr]
set btn1 [ttk::button $fr.btn1 -text "Simple click"]
set btn2 [ttk::button $fr.btn2 -text "Shift click"]
pack $btn1 $btn2
pack $fr

bind $btn1 <Button-1> {puts "Simple click"}
bind $btn2 <Shift-Button-1> {puts "Shift click"}

puts -nonewline "Press <Enter> to watch a message appear ... "
gets stdin
event generate $btn1 <Button-1>
puts -nonewline "Press <Enter> to watch another message appear ... "
gets stdin
event generate $btn2 <Button-1> -state 31
---
The trick is the '-state 31' to achieve a 'Shift click'. I discovered
this flag / option on the event manual page where it was mentioned
that it 'Corresponds to the %s substitution for binding scripts.'
Then it was only a matter of trying out what a 'Shift click' produced
with '%s'.

I hope this will be useful to some of you some time ...
Helmut

Date Sujet#  Auteur
5 Aug 24 * Generate <Shift-Button> event on a canvas (on Windows)4Helmut Giese
6 Aug 24 +- Re: Generate <Shift-Button> event on a canvas (on Windows)1Helmut Giese
6 Aug 24 `* Re: Generate <Shift-Button> event on a canvas (on Windows)2Helmut Giese
6 Aug 24  `- Re: Generate <Shift-Button> event on a canvas (on Windows)1Helmut Giese

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal