Deutsch English Français Italiano |
<mailman.90.1731322126.4695.python-list@python.org> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!2.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!not-for-mail From: John O'Hagan <research@johnohagan.com> Newsgroups: comp.lang.python Subject: SOLVED: Tkinter button-motion event behaves differently under Windows and Linux Date: Mon, 11 Nov 2024 21:46:16 +1100 Lines: 68 Sender: "John O'Hagan" <johnmohagan@gmail.com> Message-ID: <mailman.90.1731322126.4695.python-list@python.org> References: <290a97ea3b1843d786daddd43869d851f604695c.camel@johnohagan.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de Fj0Te4u7qEqPeev4atBeGA63x0bX+PMNPZec+4aZcolw== Cancel-Lock: sha1:zrhtOh8nuxL97L7XKibUEMAxlxE= sha256:9WSV6N/bM2Q/xBqywqAA7aHTG4+TpiWFNMslj3RIOeY= Return-Path: <johnmohagan@gmail.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=gmail.com header.i=@gmail.com header.b=hxP9vtFm; dkim-adsp=pass; dkim-atps=neutral X-Spam-Status: OK 0.102 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.80; '*S*': 0.01; 'def': 0.04; 'subject:event': 0.04; 'else.': 0.07; 'linux,': 0.07; 'subject:Windows': 0.07; 'tkinter': 0.07; 'linux': 0.09; 'widgets': 0.09; 'import': 0.15; 'bindings': 0.16; 'lambda': 0.16; 'solved': 0.16; 'suggestions,': 0.16; 'widgets.': 0.16; 'to:addr :python-list': 0.20; 'issue': 0.21; 'problem,': 0.22; 'lines': 0.23; 'code': 0.23; "i'd": 0.24; '(and': 0.25; 'anyone': 0.25; 'seems': 0.26; 'else': 0.27; 'think': 0.29; 'header:User-Agent:1': 0.30; 'window': 0.32; 'but': 0.32; 'received:192.168.1': 0.32; "i'm": 0.33; 'there': 0.33; 'focus': 0.33; 'received:google.com': 0.34; 'windows': 0.34; 'same': 0.34; 'target': 0.36; 'received:192.168': 0.37; 'way': 0.38; 'thanks': 0.39; "that's": 0.39; 'text': 0.39; 'to.': 0.39; 'something': 0.40; 'method': 0.61; 'skip:o 10': 0.61; 'above': 0.62; 'button': 0.64; 'down': 0.64; 'only,': 0.64; 'skip:t 20': 0.65; 'shows': 0.67; 'skip:e 20': 0.67; 'interested': 0.68; 'manager': 0.68; 'during': 0.69; 'further': 0.69; 'cast': 0.69; 'longer': 0.71; 'documented': 0.76; 'position': 0.81; 'left': 0.83; 'eventually': 0.84; 'maintains': 0.84; 'mouse': 0.84; 'released.': 0.84; 'sender:addr:gmail.com': 0.84; 'subject: \n ': 0.84; 'down,': 0.91; 'positions': 0.96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731322123; x=1731926923; darn=python.org; h=mime-version:user-agent:content-transfer-encoding:date:to:from :subject:message-id:sender:from:to:cc:subject:date:message-id :reply-to; bh=D3L4BO8orKZsxzJTT8LhLBjg5unuJM+Rd1CCi9Tum4k=; b=hxP9vtFmasy2kdeTlvW0G+v+7eggI1bBrHneTe8VxuSU5MvMnwZG6vUz89kxIEZ1+5 V3R09gDpYhxLL4DERn8rYgqYGgWuc3ct6wyBOiQ1j5irIg4C8jv5X7Q5IcIfdx+GPtdP UzGPLAzVBkwsuUi8WC3TBrPenaM4vRM9F8G2TKTxhgCvbLoCMfAh0IK8kbNfOdIO0JC2 r2xYOiVf0nVtoKHxV8vswm6gJusEhtv8aaxflnzs1cmuqLIunQiHwgCHOX4x1ExIbblq jiK2CXYCJGHoJdfzLeARg4YA4d+z86+rMRNtmKxCscjJHk0vHfAH2ReGZsquLOTn/FFF ZjGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731322123; x=1731926923; h=mime-version:user-agent:content-transfer-encoding:date:to:from :subject:message-id:sender:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=D3L4BO8orKZsxzJTT8LhLBjg5unuJM+Rd1CCi9Tum4k=; b=aSEPm12Ios5LjBvNNo0clQBIWRvVbvIHUs4L9+xfpG32Xd3ZnMjj/S/9hMCNibndy0 e2U0B8JMXzsv5DVdnJjiRjVPoSW0pK4/41ZFzLVQ8n619ZandlrpuI74HR4uMCc77nyf YofMmS6UPiXfyBpQACGw/Fmxtaad/IVXWP+LSRc4Zd6K/cn5zGzQZIo+Ptn9KSJq2mBN etIbvG/sm095FbozQPiwJBfNR9gaX8hgfd0Zk785ym1ozniTsUEM3UvkZH4dJjzhykB8 f8rABbvu15vfCySW5OiZCauY99DINCZFwu950OwUE1VJP6ySqpIC1HDcHjQigBbI8px3 nMsg== X-Gm-Message-State: AOJu0Yxv+bG1DTddL0n2Wo4wZkJis2X9LHp05N22K8xlfKl0FZeBc8lz YXWIIq/zTu8C+O+L36914z9Pl6whyJi6Mcd9intRbN4sUF6hR2uyOZQ8fQ== X-Google-Smtp-Source: AGHT+IG34QsFaP8Oq1Oopg3J7ZDrE4J2n0tQmLK1cOFJrJBdksu3LsMaySI9yb26xI5Fnhmjq2ZTtg== X-Received: by 2002:a17:90b:2b45:b0:2e2:b64e:f4f7 with SMTP id 98e67ed59e1d1-2e9b177fc67mr16273109a91.29.1731322123059; Mon, 11 Nov 2024 02:48:43 -0800 (PST) User-Agent: Evolution 3.54.1-1 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: <290a97ea3b1843d786daddd43869d851f604695c.camel@johnohagan.com> Bytes: 7499 I'm posting this in case anyone else encounters the same problem, and to ask for suggestions, if any, about a better way to do it. I'm implementing a method for dragging embedded widgets on a Text widget. When the left mouse button is held down over an embedded widget and the mouse is dragged across other widgets embedded in the same parent, the original widget moves to the new positions until the button is released. Here's some minimal code: ------- from tkinter import * text =3D Text(Tk()) text.pack() def drag(e): print(e.widget) target =3D e.widget.winfo_containing(e.x_root, e.y_root) if target and target not in (text, e.widget): if text.compare(target, '>', e.widget): target =3D f'{target} + 1 char' text.window_create(target, window=3De.widget) for n in ('1', '2', '3'): l=3DLabel(text, text=3Dn, width=3D10) #l.bind('<Button-1>', lambda e:e.widget.grab_set()) l.bind('<B1-Motion>', drag) #l.bind('<ButtonRelease-1>', lambda e:e.widget.grab_release()) text.window_create(END, window=3Dl) mainloop() ------- This works as intended for me on Windows (11). The print statement always shows the name of the first selected widget while the button is held down, regardless of where the mouse is dragged to. But on Linux (Debian testing with Gnome), for me the above code only moves the widget to the first new position it is dragged to, any further dragging is ineffective, and the print statement shows the names of the subsequently-traversed widgets. There is a further issue in the real code (not shown here) also on Linux only, where if the cursor traverses any other widgets bound to '<B1-Motion>', they are also triggered, which is not intended. Just a guess, but it seems that on Linux, the focus switches to whatever widget is under the cursor even during dragging, so any bindings on the originally-clicked widget are no longer triggered, whereas Windows maintains focus on the originally-clicked widget during dragging until the button is released. If that's the case (and I never thought I'd say this), I think Windows is right! But for all I know it might be the window manager or something else. I eventually figured out that the commented lines calling grab_set and grab_release solved the issue for me on Linux. I haven't found this documented anywhere and I'm interested to know if anyone can cast any light on it. Thanks=20