Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Things are not as simple as they seems at first. -- Edward Thorp


devel / comp.lang.python / Re: Tkinter ttk Treeview binding responds to past events!

SubjectAuthor
o Re: Tkinter ttk Treeview binding responds to past events!Mirko

1
Re: Tkinter ttk Treeview binding responds to past events!

<mailman.289.1694544688.23016.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23977&group=comp.lang.python#23977

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: mirkok.l...@googlemail.com (Mirko)
Newsgroups: comp.lang.python
Subject: Re: Tkinter ttk Treeview binding responds to past events!
Date: Tue, 12 Sep 2023 20:51:24 +0200
Lines: 63
Message-ID: <mailman.289.1694544688.23016.python-list@python.org>
References: <ffeca85a797b7a25f2a37ce7910b179c627f82c7.camel@johnohagan.com>
<084a1cfa-8889-3acd-d19c-8f204c314b7b@googlemail.com>
<b9d34cdf5dc70ddf8f3a3fdc5df1ea1ee5e6a5a4.camel@johnohagan.com>
<da4e9af8-42da-fd29-b12f-ef149f7f6b92@googlemail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de gXRMcj9Ts0pLuvZLquj00wNMb2lNOREtvySTu0s8NZug==
Cancel-Lock: sha1:FfBNW0p/CwufexyPFM8H/DCEPOg= sha256:SLg8AYX1k4u86duZ3juUsDnA2W4v6DvEKSUsLmD9+mk=
Return-Path: <mirkok.lists@googlemail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=googlemail.com header.i=@googlemail.com header.b=ZYDbyVUG;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.012
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'looks': 0.02; 'def': 0.04;
'tkinter': 0.07; 'delay': 0.09; 'from:addr:googlemail.com': 0.09;
'indeed.': 0.09; 'message-id:@googlemail.com': 0.09; 'schrieb':
0.09; 'solving': 0.09; 'import': 0.15; "(i'm": 0.16; 'purely':
0.16; 'specify': 0.16; 'python': 0.16; 'to:addr:python-list':
0.20; 'issue': 0.21; 'returns': 0.22; 'skip:_ 10': 0.22; "what's":
0.22; 'version': 0.23; 'bit': 0.27; 'header:User-Agent:1': 0.30;
'seem': 0.31; 'actions': 0.32; 'happening': 0.32; 'performed':
0.32; 'but': 0.32; "i'm": 0.33; '100': 0.33; "didn't": 0.34;
'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34;
'using': 0.37; 'class': 0.37; 'though': 0.37; 'still': 0.40;
'here.': 0.61; 'true': 0.63; 'events': 0.63; 'order': 0.69; 'it:':
0.69; 'temporarily': 0.69; 'subject:!': 0.76; 'received:37': 0.78;
'callback': 0.84; 'rob': 0.84; 'that!': 0.84; 'reliable.': 0.91;
'return.': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=googlemail.com; s=20221208; t=1694544686; x=1695149486; darn=python.org;
h=content-transfer-encoding:in-reply-to:from:references:to
:content-language:subject:user-agent:mime-version:date:message-id
:from:to:cc:subject:date:message-id:reply-to;
bh=HV5tyJFjhBG42j0+DDkF+J1Z7smO8B9qhL18m7/o2hM=;
b=ZYDbyVUGkWmndO8r8RLCh4518j4FmqS3C5W2V24A/kpgkB7XYE3g5o1QCyVWdkDfSe
8eqYI6MPHa4r7x+eOEAzc6n66ox2HkZCVkC6Mj4gL4T8bDYvywpobu6ctHRtFHgyIMfs
oP/iz8YHlT/O66m7guZmvm8iwVYn++r8C0+r9mhj3UB55KELH5/a63gkj8Qx5wWdEqBX
gpKiplHx7OZRqo5dz+J3KBrpBycjeQwgCYK4/L+BHcK1gW2TRoTCATFAZCIBhuetbZX6
tihpbiviWV4mlkQkMJbCCUtgIHRr0SvO4Px/zktTd7KRO8IzkvWC++opp06pSmNzxEFE
zYhQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1694544686; x=1695149486;
h=content-transfer-encoding:in-reply-to:from:references:to
:content-language:subject:user-agent:mime-version:date:message-id
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=HV5tyJFjhBG42j0+DDkF+J1Z7smO8B9qhL18m7/o2hM=;
b=pzD5XaWrPH36aXEZp/xHLhpAxgfxZAKJNG2JssughcK/9+/1rxzmGQFctvkl51D+LY
nb5qIJBSTMoMomE2x40X+LdLTB3NysXjb1Hs/ID3eQUavRnH2z9xCFR/VZZuj85eoKdY
NsOBAayqUEAAPCHjz6K6dcaby9zSgTuaYaoCjGn6yiOJMUPrWLykKtssDR/rOAbjatO8
YzxynfWslWFRxSKPDM0cNr8Ygv3o2p8bKjOVNg0UzX25AC7Yt67acIbem/ZtEOMADrkO
BzFBkUWTFfbE2DiucVQ9+PZAGPz9j2tYe0l7bUnLamwOPWhrSTNNM72y7FSKMACnS3ts
Elkg==
X-Gm-Message-State: AOJu0YwSrvmcdYE3gCb6sapoAuM/N/YTLKkowpXJOR6zQ4TLNkITR0Ve
YtI5d1BqkKeGrNnc0DN47ZiyN4f1FGI=
X-Google-Smtp-Source: AGHT+IH3LStxKKsHkkYbBVc/Bvhk5XBLWkTd8e9frX3lr2yJeenaLDWFUVR7xikosezRURlk+2AHlQ==
X-Received: by 2002:a17:906:1da9:b0:9ad:78b7:29e8 with SMTP id
u9-20020a1709061da900b009ad78b729e8mr146895ejh.39.1694544686302;
Tue, 12 Sep 2023 11:51:26 -0700 (PDT)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Content-Language: de-DE, en-US
In-Reply-To: <b9d34cdf5dc70ddf8f3a3fdc5df1ea1ee5e6a5a4.camel@johnohagan.com>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <da4e9af8-42da-fd29-b12f-ef149f7f6b92@googlemail.com>
X-Mailman-Original-References: <ffeca85a797b7a25f2a37ce7910b179c627f82c7.camel@johnohagan.com>
<084a1cfa-8889-3acd-d19c-8f204c314b7b@googlemail.com>
<b9d34cdf5dc70ddf8f3a3fdc5df1ea1ee5e6a5a4.camel@johnohagan.com>
 by: Mirko - Tue, 12 Sep 2023 18:51 UTC

Am 12.09.23 um 07:43 schrieb John O'Hagan via Python-list:

> My issue is solved, but I'm still curious about what is happening here.

MRAB already said it: When you enter the callback function, Tk's
mainloop waits for it to return. So what's happening is:

1. Tk's mainloop pauses
2. temp_unbind() is called
3. TreeviewSelect is unbound
4. events are queued
5. TreeviewSelect is bound again
6. temp_unbind() returns
7. Tk's mainloop continues with the state:
- TreeviewSelect is bound
- events are queued

Am 11.09.23 um 23:58 schrieb Rob Cliffe:

> Indeed. And you don't need to specify a delay of 100 milliseconds. 0 will work (I'm guessing that's because queued actions are performed in the order that they were queued).

Ah, nice, didn't know that!

> I have also found that after() is a cure for some ills, though I
> avoid using it more than I have to because it feels ... a bit
> fragile, perhaps.
Yeah. Though for me it was the delay which made it seem fragile.
With a 0 delay, this looks much more reliable.

FWIW, here's a version without after(), solving this purely on the
python side, not by temporarily unbinding the event, but by
selectively doing nothing in the callback function.

from tkinter import *
from tkinter.ttk import *

class Test:
def __init__(self):
self.inhibit = False
root=Tk()
self.tree = Treeview(root)
self.tree.pack()
self.iid = self.tree.insert('', 0, text='test')
Button(root, command=self.temp_inhibit).pack()
mainloop()

def callback(self, *e):
if not self.inhibit:
print('called')

def temp_inhibit(self):
self.inhibit = True
self.tree.selection_set(self.iid)
self.tree.selection_remove(self.iid)
self.tree.selection_set(self.iid)
self.inhibit = False
self.callback()

c=Test()

HTH and regards

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor